while loops and vectors

9 views (last 30 days)
oselu
oselu on 14 Sep 2014
Commented: Star Strider on 14 Sep 2014
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

Accepted Answer

Star Strider
Star Strider on 14 Sep 2014
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 Comments
oselu
oselu on 14 Sep 2014
Thank you very much:)
Star Strider
Star Strider on 14 Sep 2014
My pleasure!

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!