Save figure with all subplots

조회 수: 30 (최근 30일)
Sharon
Sharon 2019년 10월 9일
댓글: Adam Danz 2024년 10월 7일
I generated a lot of figures with subplots. I want to save them and don't want to display them.
I realized only the last subplot is saved. Is there anyway I can save all subplots in a figure.
The following is an example code.
t=linspace(1,10,20);
y=2*t;
for i=1:3
f=figure('visible','off');
subplot(1,3,i)
p=plot(t,y);
saveas(f,'test','jpg')
end
  댓글 수: 1
Trang Doan
Trang Doan 2021년 4월 19일
이동: Adam Danz 2024년 10월 7일
how to save 1 figure of the subplots

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

답변 (1개)

Walter Roberson
Walter Roberson 2019년 10월 9일
Construct new file names each iteration.
saveas(f, sprintf('test%d.jpg', i))
  댓글 수: 4
Sharon
Sharon 2019년 10월 9일
You are right. I should put saveas outside the loop.
Adam Danz
Adam Danz 2024년 10월 7일
I'd also like to point readers in the direction of exportgraphics instead of saveas.
exportgraphics(fig, filename)

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

카테고리

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