plot multiple figures, each with subplots, within three layers of for loops
조회 수: 11 (최근 30일)
이전 댓글 표시
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
답변 (1개)
José-Luis
2013년 12월 19일
counter = 1;
for ii = 1:5
for jj = 1:5
figure(counter)
%bla
counter = counter + 1;
end
end
댓글 수: 2
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 Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!