How to save a figure through each run of a for loop?

4 vues (au cours des 30 derniers jours)
Maria Y
Maria Y le 31 Jan 2019
Réponse apportée : KSSV le 1 Fév 2019
I created a for loop for a series of figures, and am trying to save each one as the for loop is running (saved as 'Delta_roseplot_forloop_Trial1.jpg', '...Trial2.jpg', '...Trial3.jpg', and so forth).
Here is what I have:
for m= 1:6
load('BR_PD10_SRTT_pwr_M1.mat')
itc_delta=itc_trial{m};
itc_delta=itc_delta(2,:,:);
itc_delta=squeeze(itc_delta);
itc_delta_keypress=itc_delta(398,:);
f1=figure;
rose(itc_delta_keypress);
for k=1:6
h=f1;
rose(itc_delta_keypress);
saveas(h,sprintf('Delta_roseplot_forloop_Trial%d.jpg',k));
end
end
But while all the figures come out right, the .jpgs are all saved looking exactly the same. I think I'm supposed to put 'hold on' somewhere, but I can't figure out where.
Would appreciate any help!
  1 commentaire
Walter Roberson
Walter Roberson le 31 Jan 2019
The only thing you change inside your for k loop is the filename to write to, so unless rose() uses random numbers internally, all of the rose plots are going to be the same.
Note: the filename you construct does not depend upon m, so you are not saving one file for each m, k combination.

Connectez-vous pour commenter.

Réponses (1)

KSSV
KSSV le 1 Fév 2019
load('BR_PD10_SRTT_pwr_M1.mat')
for m= 1:6
itc_delta=itc_trial{m};
itc_delta=itc_delta(2,:,:);
itc_delta=squeeze(itc_delta);
itc_delta_keypress=itc_delta(398,:);
figure
rose(itc_delta_keypress);
for k=1:6
rose(itc_delta_keypress);
saveas(gcf,strcat('Delta_roseplot_forloop_Trial',num2str(k),'.jpg')) ;
end
end

Catégories

En savoir plus sur Loops and Conditional Statements 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