while loops and vectors
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponse acceptée
Star Strider
le 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!