필터 지우기
필터 지우기

How can I display all the answer from while looping?

조회 수: 1 (최근 30일)
Indri Djon Hansemit
Indri Djon Hansemit 2013년 5월 7일
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.

답변 (1개)

David Sanchez
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.

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by