Rewriting a loop construct
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2014-2-1
What kind of alternative were you hoping for? It's just an "if" statement with a simple body.
采纳的回答
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
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 Center 和 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!