Save figure with all subplots

30 vues (au cours des 30 derniers jours)
Sharon
Sharon le 9 Oct 2019
Commenté : Adam Danz le 7 Oct 2024
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 commentaire
Trang Doan
Trang Doan le 19 Avr 2021
Déplacé(e) : Adam Danz le 7 Oct 2024
how to save 1 figure of the subplots

Connectez-vous pour commenter.

Réponses (1)

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

Connectez-vous pour commenter.

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by