How to save an image using imwrite with a filename from a variable
134 views (last 30 days)
I am saving a frame from a video as an image. Both the image and video should have the same name. How can I save an image with a file name from a variable? The filenames are stored in the variable videos.name
videos = dir('*.avi');
for i = 1:size(videos)
[pathstr,name,ext] = fileparts(videos(i).name)
V = VideoReader(videos(i).name);
oneframe = readFrame(V);
imwrite(oneframe, name, '.jpg')
Thank you very much!
Kirby Fears on 24 Oct 2016
Edited: Kirby Fears on 24 Oct 2016
You can combine string values using square brackets. The syntax for imwrite using your variable names is as follows:
imwrite(oneframe, [name, '.jpg']);
Check your workspace to ensure name is the intended file name without a file extension.
Hope this helps