How to break loop when successive values are too close
3 ビュー (過去 30 日間)
表示 古いコメント
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 件のコメント
採用された回答
SALAH ALRABEEI
2021 年 6 月 5 日
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 件)
Sulaymon Eshkabilov
2021 年 6 月 5 日
編集済み: Sulaymon Eshkabilov
2021 年 6 月 5 日
In this case, it can be solved using round(D, n) to set up the tolerance value. Where n is correct decimal digits.
0 件のコメント
参考
カテゴリ
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!