Effacer les filtres
Effacer les filtres

Execute a function till she reproduces twice in a row the same result

2 vues (au cours des 30 derniers jours)
Jan Borkovec
Jan Borkovec le 22 Juin 2016
Commenté : Jan Borkovec le 22 Juin 2016
I wrote a (working) function. Now i need to execute the function till she reproduces two times the same result. How do i do this?

Réponse acceptée

rocketboyjka
rocketboyjka le 22 Juin 2016
I would use a while loop. Something like this maybe: (If your function produces a 'new' value every time you call it.)
value1 = myfunctionvalue()
error = 1;
while error ~= 0
value2 = myfunctionvalue();
error = value2 - value1
value1 = value2
end
Although, really you should probably have some tolerance on the while loop (error<tolerance). If the subsequent calls don't match exactly, then the above approach could get stuck.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by