How to break the iteration using an Error Equation

2 views (last 30 days)
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

Answers (1)

Walter Roberson
Walter Roberson on 5 Dec 2013
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

Categories

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!