Effacer les filtres
Effacer les filtres

how to run a function again and again till a condition satisfies?

2 vues (au cours des 30 derniers jours)
suchismita
suchismita le 27 Avr 2015
Commenté : suchismita le 27 Avr 2015
Hello, i have a function which i want to run again and again till the condition is fulfilled.
please please help me....

Réponse acceptée

Mischa Kim
Mischa Kim le 27 Avr 2015
suchismita, see e.g.,
flag = false;
cnt = 0;
while ~flag
cnt = cnt + 1;
fprintf('Try no.: %d\n', cnt);
if (rand() < 0.25)
flag = true;
end
end
Your function would simply reside inside the loop.

Plus de réponses (1)

Stephen23
Stephen23 le 27 Avr 2015
Modifié(e) : Stephen23 le 27 Avr 2015
This is what a while loop is for. There are good examples in the documentation too:
And this is a good place to look when you want to control your program somehow:

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by