필터 지우기
필터 지우기

Rewriting a loop construct

조회 수: 1 (최근 30일)
Ayesha
Ayesha 2014년 2월 1일
편집: Walter Roberson 2014년 2월 1일
Just a thought guys, how would you rewrite this loop construct?
if i < 4
subplot(4,1,i+1);
plot(x,y);
title('Original');
end
I did try to write it as follows but something went wrong outside the loop:
subplot(4,1,i+1);
plot(x,y);
title('Original');
if i==2
break
end
What do you think of other loop constructs?
  댓글 수: 5
Ayesha
Ayesha 2014년 2월 1일
So could if be replaced by any other construct?
Walter Roberson
Walter Roberson 2014년 2월 1일
What kind of alternative were you hoping for? It's just an "if" statement with a simple body.

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

채택된 답변

Sneheet
Sneheet 2014년 2월 1일
편집: Sneheet 2014년 2월 1일
if you want to plot for i=1 to i=4,
for i=1:4
subplot(4,1,i+1);
plot(x,y);
title('Original');
end
  댓글 수: 1
Walter Roberson
Walter Roberson 2014년 2월 1일
편집: Walter Roberson 2014년 2월 1일
To be consistent, the upper end of the loop should be 3 rather than 4. The lower end could be adjusted to 0 instead of 1.

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

추가 답변 (0개)

카테고리

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