How to assign names to save different figures?
Mostra commenti meno recenti
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!
Risposta accettata
Più risposte (1)
Image Analyst
il 27 Giu 2014
If you want to give a particular name to the figure's title bar, you can do this:
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
Or if you want to embed some variable's value into the name, you can do this:
% Give a name to the title bar.
itsName = sprintf('The parameter value in this figure is %.3f', someValue);
set(gcf, 'Name', itsName, 'NumberTitle', 'Off')
Categorie
Scopri di più su Whos in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!