How to break loop when successive values are too close

조회 수: 2 (최근 30일)
SANDEEP SINGH RANA
SANDEEP SINGH RANA 2021년 6월 5일
댓글: SALAH ALRABEEI 2021년 6월 5일
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?

채택된 답변

SALAH ALRABEEI
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
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.

카테고리

Help CenterFile Exchange에서 Global or Multiple Starting Point Search에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by