how to increment variable while logical true?
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
akshay raj
le 21 Jan 2015
Commenté : akshay raj
le 21 Jan 2015
Hi,
I am new to matlab, I want to increment a number when its true.
i tried doing this as a script
global variable;
variable = true;
while (variable)
a=1;
a=a+1;
dips(a);
end
shouldn't this display an incremented value
1
2
3
4
.
.
.
but all i get is
2
2
2
2
.
.
Am i doing something wrong? help!
0 commentaires
Réponse acceptée
Image Analyst
le 21 Jan 2015
Modifié(e) : Image Analyst
le 21 Jan 2015
You're setting a back equal to 1 inside the loop. Why? That should be outside the loop. I think you should look at this: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
global variable;
variable = true;
a = 1;
while variable
a=a+1
if a > 20
variable = false; % Break out of loop.
end
end
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!