Get Title/String of all figures of a scripts
2 views (last 30 days)
Show older comments
Hello,
I am working on a script with several figures as an output. I want to save all of them without saving as individual, I tried:
FolderName = tempdir;
FigList = findobj(allchild(0), 'flat', 'Type', 'figure');
for iFig = 1:length(FigList)
FigHandle = FigList(iFig);
FigName = get(FigHandle, 'Name');
savefig(FigHandle, fullfile(FolderName, [FigName, '.fig']));
end
The problem with this it get only figure handles (gcf) which don't have Title/String that I want to use as a file name to save it. Title is accessible with get(gca) but it will only work for individual figure at a time not for all at once.
Any help will be appreciated.
1 Comment
Jeroen Christiaens
on 14 Apr 2021
Edited: Jeroen Christiaens
on 14 Apr 2021
Hi
The following code worked for me.
FolderName = 'tempdir'; % Your destination folder
% folder = mkdir(FolderName) ;
FigList = findobj(allchild(0), 'flat', 'Type', 'figure');
for iFig = 1:length(FigList)
FigHandle = FigList(iFig);
ax = FigHandle.CurrentAxes;
FigName = get(ax,'title');
FigName = get(FigName, 'string');
savefig(FigHandle, fullfile(FolderName, strjoin({FigName, '.fig'},'')));
end
Answers (0)
See Also
Categories
Find more on Printing and Saving 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!