Save the data of each iteration of a for loop followed by a convergence criteria

1 view (last 30 days)
Dear all
I have a set of for-loop iterations from j=1 to j=120 which is running an algorithm inside it. I want to save the data of a particular output variable say, YMF{i} for each iteration and as a convergence criteria of the simulation I want to check that if the values of ((YMF(j-1) - YMF(j))/YMF(j-1)) <= 0.02.
I dont know how to introduce iteration number i.e j along with row number i.e i to perform the above task.
N.B: YMF is a variable having 500 rows(i) that has been stored in cell arrays for each iteration.
Please help. I am new to MATLAB. Any help is highly appreciated. I would be grateful to provide any other data if you might need to address the issue. Thanks in advance.
store= zeros(500,120) % preallocate a matrix of 500 rows and 120 columns(iteration number)
while ((store{i,(j-1)} - store{i,(j)})/store{i,(j-1)}) <= 0.02 | (j<120)
j=j+1;
store(:,j)= [YMF{i}]
end

Answers (0)

Community Treasure Hunt

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

Start Hunting!