Create a cell array to store the frame and use the sprintf function to not overwrite the frames acquired. this is an example
vid = videoinput('winvideo',1); set(vid, 'FramesPerTrigger', Inf); set(vid, 'ReturnedColorspace', 'rgb'); i = 1; while true data{i} = getsnapshot(vid); imwrite(data{i}, sprintf('imageName%d.jpg',i))%save in the current folder imshow(data{i}); i=i+1; pause(5); end