How can I display all the answer from while looping?
2 ビュー (過去 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!