Effacer les filtres
Effacer les filtres

Create Figures in a loop

7 vues (au cours des 30 derniers jours)
Sara Nikdel
Sara Nikdel le 18 Août 2022
Commenté : Sara Nikdel le 22 Août 2022
Hi,
I am trying to create multiple figures using a for loop, but I am not sure how it is done? I also need to save them as jpeg files with their specific names.
figures = [];
% Generate figures
for i=1:10
figures(i)
histogram(r(i,:),'Normalization','probability');
xlim([0, 2*Mean(1,i)]);
ylabel('Probability')
title(i,'th end-event')
saveas(figures(i),i,'th end-event.jpg')
end

Réponses (1)

Jan
Jan le 18 Août 2022
Modifié(e) : Jan le 18 Août 2022
fig = gobjects(1, 10);
for i = 1:10
fig(i) = figure();
histogram(r(i,:),'Normalization','probability');
xlim([0, 2*Mean(1,i)]);
ylabel('Probability')
title(sprintf('%dth end-event', i);
saveas(fig(i), sprintf('%dth end-event.jpg', i));
end
See: sprintf
  1 commentaire
Sara Nikdel
Sara Nikdel le 22 Août 2022
Thank you :)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Migrate GUIDE Apps 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