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


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
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.