how to terminate loop when i get desired result
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
i am sloving a matrix, which is in time loop (for). I want this time loop stop and present final output once the output matrix starts repeating itself.
0 commentaires
Réponses (1)
KSSV
le 25 Juin 2021
Modifié(e) : KSSV
le 25 Juin 2021
t0 = randperm(100,1) ; % give some value
tol = 10^-3 ; % mention the accuracy you want
for i = 1:10000
% find your output here
t1 = randperm(100,1) ; % random value for demo
if abs(t0-t1) < tol
break
else
t0 = t1 ;
end
end
[t0 t1 i]
0 commentaires
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!