while loops and vectors

조회 수: 6 (최근 30일)
oselu
oselu 2014년 9월 14일
댓글: Star Strider 2014년 9월 14일
hello everyone
Is there a way to store the answers from a while loop in a vector?? Id like to know how to do that. I know its possible with for loops
thank you

채택된 답변

Star Strider
Star Strider 2014년 9월 14일
It is. You simply have to create a counter:
k1 = 1;
x = 0;
while x < 25
x = k1^2; % Calculate ‘x’
y(k1) = x; % Store the value of ‘x’ in vector ‘y’
k1 = k1 + 1; % Increment counter
end
  댓글 수: 2
oselu
oselu 2014년 9월 14일
Thank you very much:)
Star Strider
Star Strider 2014년 9월 14일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by