Get Title/String of all figures of a scripts

2 Ansichten (letzte 30 Tage)
Shaheryar Ahmad
Shaheryar Ahmad am 11 Dez. 2018
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 Kommentar
Jeroen Christiaens
Jeroen Christiaens am 14 Apr. 2021
Bearbeitet: Jeroen Christiaens am 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

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Printing and Saving finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by