How can I display all the answer from while looping?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I'm a beginner. I tried practise with looping "while". The following codes were :
%whilelooping
a=4;
b=2;
c=a/b;
while c>1
a=a-1;
c=a/b;
end
disp(a);
disp(b);
disp(c);
And the answer was 2 2 1. I don't understand how to make the answer become : a=4 3 2, b=2 2 2, c=2 1.5 1. Need help, thank you for advice.
0 Kommentare
Antworten (1)
David Sanchez
am 7 Mai 2013
Since you are using disp() outside the while loop, only after exiting the while-loop the disp() comes to play, displaying the last value of the variables. Note that if you do not add semicolon at the end of a line, the value of the variable acting on that line will be displayed on the command widow ( as below )
a=4;
b=2;
c=a/b;
while c>1
a=a-1
b
c=a/b
end
But this code will not present your data in array format either, since your variables are not arrays. To do so, you should redefine your variables as such and think again what you want to do.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Whos 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!