For loop within a for loop doesn't quite work!

조회 수: 1 (최근 30일)
Olivia Milton-thompson
Olivia Milton-thompson 2015년 10월 15일
댓글: Olivia Milton-thompson 2015년 10월 15일
I have this for loop inside a for loop which I've created to develop a scatter plot and it almost works, except after the first iteration it seems to only be looping back via the second loop and ignoring the first one each time. How do I prevent that and make sure it loops with the first, then second, then first then second etc?
fig = figure();
x = T2{:,10};
for i = 2:9
y = T2{:,i};
for j = 1:6;
axj = subplot(2,3,j);
scatter(axj,x,y,'filled');
end;
end;
Thank you!!
  댓글 수: 1
Olivia Milton-thompson
Olivia Milton-thompson 2015년 10월 15일
Sorry the code was slightly wrong. This is the corrected version. I basically want 8 different graphs and they are different according to "i".
fig = figure();
x = T2{:,10};
for i = 2:9
y = T2{:,i};
for j = 1:8;
axj = subplot(2,4,j);
scatter(axj,x,y,'filled');
end;
end;

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

답변 (1개)

Walter Roberson
Walter Roberson 2015년 10월 15일
You need "hold on" after the first scatter() call
  댓글 수: 2
Olivia Milton-thompson
Olivia Milton-thompson 2015년 10월 15일
Ye i tried that but it just plotted the same thing on every graph :(
Olivia Milton-thompson
Olivia Milton-thompson 2015년 10월 15일
편집: Olivia Milton-thompson 2015년 10월 15일
also theres only one scatter...what do you mean after the first one?

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by