plot multiple figures, each with subplots, within three layers of for loops
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a three layer nested for loop situation, I want to generate three figures in for loop "3" where each iteration of for loop "2" inserts subplots into each of the three and each iteration of for loop "1" generates its own set of three figures in for loop "3" to be populated with the subplots from loop "2".
I have code structured like this:
rawdata={'file1' 'file2' 'file3'};
field=[280 300 320];
vars=[1 2 3 4];
varst=[0,1,2,3];
varen=[2,3,4,5];
index=6;
for a=1:length(vars)
for b=1:index
linc(a)=(varen(a)-varst(a))/index;
xd=vars;
xd(b)=((b-1)*linc(b))+varst(b);
for c=1:length(field)
[data]=processing(rawdata{c});
[spec freq]=function(vars,field(c))
figure(c*a);
subplot(3,3,b);plot(freq,spec);
subplot(3,3,8);plot(freq,data);
end
end
end
This works except there are repeats of the figure index at certain combinations of a and c (for example: when a=2 and c=1, this overwrites the figure for a=1 and c=2.) I've tried a bunch of methods for getting around this but nothing has worked. Does anyone know how to do this?
Thanks!
0 commentaires
Réponses (1)
José-Luis
le 19 Déc 2013
counter = 1;
for ii = 1:5
for jj = 1:5
figure(counter)
%bla
counter = counter + 1;
end
end
2 commentaires
José-Luis
le 19 Déc 2013
I'm sorry but I don't understand what you mean. Do you want to overwrite some of the figures only? You could explicitly store your figure and axes handles and just modify what you need when you need it:
fH = figure(1);
aH = subplot(3,3,9);
plot(aH, rand(10,2));
Voir également
Catégories
En savoir plus sur Subplots 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!