How can I display all the answer from while looping?
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
David Sanchez
2013-5-7
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!