Save all the plots

조회 수: 362 (최근 30일)
Konstantinos
Konstantinos 2015년 3월 11일
Each time I run my code it produces 100 figures. So, I have to waste my time and save each one of them. Is there a command that can do that work for me by saving all the figures at once?
  댓글 수: 1
Hira
Hira 2022년 9월 27일
m=1;
title("S31 Plot Measurement Number ("+m+")")
xlabel('Delay')
ylabel('Mag(S31)')
saveas(gcf,"S31_plot_"+name+"_Measurement_No_"+m+".fig")
close(gcf)
m=m+1;

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2015년 3월 11일
No, there is no such command. But it is easy to write one:
FolderName = tempdir; % Your destination folder
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
Adjust the FigName to your needs.
  댓글 수: 5
Lars Abrahamsson
Lars Abrahamsson 2020년 5월 18일
I noticed one "problem" when saving all figures into one file.
When loading them back with "openfig" the numbers/order of the figures becomes revered.
Why is that? Can anything be done to counteract that?
Brandon Laflen
Brandon Laflen 2020년 5월 19일
If they load backwards, I'm guessing findobj is LIFO. Maybe try
savefig(FigList(end:-1:1),filename)
instead?

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Luke Shaw
Luke Shaw 2018년 11월 30일
편집: Luke Shaw 2018년 11월 30일
Missed a make current step: set(0, 'CurrentFigure', figureHandle)
FolderName = tempdir; % Your destination folder
FigList = findobj(allchild(0), 'flat', 'Type', 'figure');
for iFig = 1:length(FigList)
FigHandle = FigList(iFig);
FigName = num2str(get(FigHandle, 'Number'));
set(0, 'CurrentFigure', FigHandle);
savefig(fullfile(FolderName, [FigName '.fig']));
end
  댓글 수: 5
Nabil Mederbel
Nabil Mederbel 2022년 6월 11일
Hi guys,
I tried to save figures with '.eps' format ...didnt work.
any idea ? thx
José Ángel Sevillano Caraballo
This worked for '.png' format, it should work for whatever format you want.
FolderName = tempdir; % Your destination folder
FigList = findobj(allchild(0), 'flat', 'Type', 'figure');
for iFig = 1:length(FigList)
FigHandle = FigList(iFig);
FigName = num2str(get(FigHandle, 'Number'));
set(0, 'CurrentFigure', FigHandle);
saveas(FigHandle,fullfile(FolderName, [FigName '.png'])); %Specify format for the figure
end

댓글을 달려면 로그인하십시오.


Tanveer
Tanveer 2022년 9월 18일
FolderName = 'xx'; % Your destination folder
FigList = findobj(allchild(0), 'flat', 'Type', 'figure');
for iFig = 1:length(FigList)
FigHandle = FigList(iFig);
FigName = ['Fig' num2str(iFig)];
savefig(FigHandle, fullfile(FolderName, [FigName '.fig']));
saveas(FigHandle, fullfile(FolderName, [FigName '.png']));
% saveas(FigHandle,filename,formattype)
end

Mehri Mehrnia
Mehri Mehrnia 2022년 8월 3일
Based on the answers, it means there is no 1 line of code which can save all open plots?
  댓글 수: 1
Hira
Hira 2022년 9월 27일
m=1;
title("S31 Plot Measurement Number ("+m+")")
xlabel('Delay')
ylabel('Mag(S31)')
saveas(gcf,"S31_plot_"+name+"_Measurement_No_"+m+".fig")
close(gcf)
m=m+1;

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by