MATLAB Answers

I want to save multiple images in a folder?

125 views (last 30 days)
I made the code but the looping variable comes in the string function so a single image is saved in the folder. Is any other way of separating the looping variable from the colon bars.
img=imread('cameraman.tif');
for i=1:5
img=imread('http://satellite.imd.gov.in/img/3Dnesec_ir1.jpg')
imwrite(img,'D:\output database\i.jpg','jpg')% x be a image to write
end

  0 Comments

Sign in to comment.

Accepted Answer

Jan
Jan on 15 Mar 2018
Edited: Jan on 26 Aug 2019
for k = 1:5
FileName = sprintf('D:\\output database\\%d.jpg', k)
...
end

  3 Comments

Ali Shahid
Ali Shahid on 23 Aug 2019
This works fine.
for k = 1:5
FileName = sprintf('D:/output database/%d.jpg', k)
...
end
Stephen Cobeldick
Stephen Cobeldick on 26 Aug 2019
Using fullfile makes the path definition simpler:
for k = 1:5
FileName = fullfile('D:\output database',sprintf('%d.jpg',k))
...
end

Sign in to comment.

More Answers (0)

Sign in to answer this question.