MATLAB: How to preserve data in array in function during multiple calls of it.

functionMATLAB

Greetings,
I have a loop that calls a function that writes data into array.
For example:
function myfunction(nmax,n)
if n==1
A = zeros(1,nmax) % called only the first time
end
A(1,n)=3
end
During second call of the function, the value in the first column becomes 0, while value in the second column is valid, and so on. Also, number of columns is not nmax anymore.
How to preserve data in array during multiple calls of function?

Best Answer

I do not entirely understand what you are doing.
Consider using your array as a persistent (link) variable.