Hi all,
I'm cropping out certain parts of an image using imcrop function, which opens them in new figures. I would then like to save those figures as separate .tif images into a specific folder and then repeat for other images. In such a way in one folder I would like to write new images as 'figure_%d.tif' after the already existent images. Here's the code I have at the moment:
files = dir( fullfile(folder_name,'*tif') ); %list all figure files
file = {files.name}; name=file{:,end}; shortname1=name(1:6);%extract 'figure' from the file to make sure it's of the same kind
if shortname1=='figure' shortname2=name(1:end-4);%find the number of file
n=str2num(shortname2(end));%returns the number of the file
for k=(n+1):(n+numel(figures)) baseFileName = sprintf('figure_%d.tif',k); fullFileName = fullfile(folder_name,baseFileName); figlist=findobj(gcf);%find all images in opened figures
for i=1:numel(figlist) saveas(figlist(i),fullFileName); end end end
The problem is, it saves only the last opened figure several times instead of saving each figure with a set baseFileName. Could anyone please help me to sort it out?
Thanks in advance!
Best Answer