How to break loop when successive values are too close
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
SANDEEP SINGH RANA
am 5 Jun. 2021
Kommentiert: SALAH ALRABEEI
am 5 Jun. 2021
I want to exit from the loop when successive matrix value is too close.For example:. For n=1:100 If f(n+1)==f(n) Break; end; end; It also good if I compare upto 4 digits or some tolerance value. Is there any matlab function is there for it?
0 Kommentare
Akzeptierte Antwort
SALAH ALRABEEI
am 5 Jun. 2021
check this example;
% examle
tol=1e-4
xold=1e10
for i =1:100
xnew = ....
if abs(xnew-xold) < tol
break
end
xold=xnew;
end
1 Kommentar
Weitere Antworten (1)
Sulaymon Eshkabilov
am 5 Jun. 2021
Bearbeitet: Sulaymon Eshkabilov
am 5 Jun. 2021
In this case, it can be solved using round(D, n) to set up the tolerance value. Where n is correct decimal digits.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!