Rewriting a loop construct
古いコメントを表示
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
2014 年 2 月 1 日
Walter Roberson
2014 年 2 月 1 日
That is not a loop. "if" does not cause looping: the body of the "if" is done once if the condition is true. Using a loop requires "for" or "while"
Ayesha
2014 年 2 月 1 日
Walter Roberson
2014 年 2 月 1 日
What kind of alternative were you hoping for? It's just an "if" statement with a simple body.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!