MATLAB: Comparing updated array from two consecutive iterations

arrayforloopwhile

Hi, I need to create a while loop for a for loop which iterates until the difference between the array c of the current iteration and the array c of the previous iteration is small. Any suggestions on how I could save the updated array for each iteration and then compare the 2 consecutive iterations?

Best Answer

Like this:
prv = 0; % pick first previous value
for ...
new = ...
...compare prv & new, do whatever
prv = new;
end