Get Title/String of all figures of a scripts

9 vues (au cours des 30 derniers jours)
Shaheryar Ahmad
Shaheryar Ahmad le 11 Déc 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 commentaire
Jeroen Christiaens
Jeroen Christiaens le 14 Avr 2021
Modifié(e) : Jeroen Christiaens le 14 Avr 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

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Printing and Saving dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by