Rewriting a loop construct
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ayesha
am 1 Feb. 2014
Bearbeitet: Walter Roberson
am 1 Feb. 2014
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 Kommentare
Walter Roberson
am 1 Feb. 2014
What kind of alternative were you hoping for? It's just an "if" statement with a simple body.
Akzeptierte Antwort
Sneheet
am 1 Feb. 2014
Bearbeitet: Sneheet
am 1 Feb. 2014
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 Kommentar
Walter Roberson
am 1 Feb. 2014
Bearbeitet: Walter Roberson
am 1 Feb. 2014
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!