How to save a figure through each run of a for loop?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Walter Roberson
am 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.
Antworten (1)
KSSV
am 1 Feb. 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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!