Get Title/String of all figures of a scripts

2 次查看(过去 30 天)
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 个评论
Jeroen Christiaens
Jeroen Christiaens 2021-4-14
编辑:Jeroen Christiaens 2021-4-14
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

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by