How to break the iteration using an Error Equation

조회 수: 2 (최근 30일)
Khaled Fouda
Khaled Fouda 2013년 12월 5일
답변: Walter Roberson 2013년 12월 5일
I have a 2D for loop iteration, I want to stop the iteration once change is less than a certain number! But I don't know how to recall the previous iteration?
Let's say equation is:
Iteration i=1:20000
x=function
y=function
result is A(x,y)
How to calculate change between the A at any i and i-1?
If I want the stop iterating (break the loop) when the change is <1 for example
I don't want to use A(x,y,i) code because my iteration sometimes stop changing at 20000 or so, that will require a huge memory
Thanks in advance

답변 (1개)

Walter Roberson
Walter Roberson 2013년 12월 5일
oldvalue = inf;
for i = 1 : 200000
x = function
y = function
T = value that will go into A(x,y)
A(x,y) = T;
if abs(T - oldvalue) < Tolerance
break
end
oldvalue = T;
end

카테고리

Help CenterFile Exchange에서 Digital Filtering에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by