How to break loop when successive values are too close
2 次查看(过去 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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!