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
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 Center 和 File Exchange 中查找有关 Printing and Saving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!