Did you read the documentation already? doc snapshot. You have to create the "cam" object e.g. by cam = webcam('Logitech'). In your code, the image is obtained by imread(url) already, so simply replace:
cam = imread(url); img= snapshot(cam); imshow(img);
by
img = imread(url); imshow(img);