plot multiple figures, each with subplots, within three layers of for loops

조회 수: 11 (최근 30일)
Thomas Casey
Thomas Casey 2013년 12월 19일
댓글: José-Luis 2013년 12월 19일
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!

답변 (1개)

José-Luis
José-Luis 2013년 12월 19일
counter = 1;
for ii = 1:5
for jj = 1:5
figure(counter)
%bla
counter = counter + 1;
end
end
  댓글 수: 2
Thomas Casey
Thomas Casey 2013년 12월 19일
I've tried that, it gives a new figure window for every subplot meaning "b" figures for every "a" iteration. I want only three figures for each iteration of "a", each having "b+1" subplots where the +1 is the data plot that stays unchanged for each "b" iteration. Each of the three figures correspond to one of the "field" values.
I can make the three data figures before the loops and add the subplots to them if the "a" index is 1. But if I want the "a" to be longer than 1, is there a way to duplicate the three figures, keep the old ones, and update the three new ones so that they correspond to the new "a" value and then fill in with the "b" iterations at that "a"? That might be faster too.
José-Luis
José-Luis 2013년 12월 19일
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));

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by