Save figure as image to folder with continuous numbering
Show older comments
if i use this code all the picture that were there previously are overwritten by the last one. i would like that it names the files like this 1.jpg,2.jpg, and so on . . . and not overwrite the files!
%
filename = fullfile(folder, baseFileName);
img = getframe(gcf);
folder = 'C:\Users\Taiko\Desktop\FalseColor\';
ImageFiles = dir(folder);
a = length(ImageFiles)-1;
for Index = 1:a
baseFileName = [num2str(Index),'.jpg'];
imwrite(img.cdata,fullfile(folder,baseFileName));
end
if exist(filename, 'file')
promptMessage = sprintf('%s already exists.\nDo you want to overwrite it', filename);
titleBarCaption = 'Overwrite?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Yes', 'No', 'Yes');
if strcmpi(buttonText, 'Yes')
imwrite(img.cdata,filename);
end
else
imwrite(img.cdata,filename);
end
i got the code from this post put it got never resolved: https://de.mathworks.com/matlabcentral/answers/289707-how-to-prevent-image-that-has-been-stored-not-overwrite-using-imwrite
edit: i have a script that makes false color images and i would like to whenever i run the script that it saves the output image in that folder and labeling them continuously 1.jpg and so on
3 Comments
Walter Roberson
on 6 Aug 2017
It is not clear why you have a loop that writes sequential files 1.jpg, 2.jpg, etc., one for every existing file (with any name) inside the folder (skipping the last one), with all of the files having the same content. And then that, having been done, a test is made about overwriting a completely different file name ??
franz binder
on 6 Aug 2017
Edited: franz binder
on 6 Aug 2017
franz binder
on 7 Aug 2017
Accepted Answer
More Answers (0)
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!