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

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

Accepted Answer

Star Strider
Star Strider on 1 May 2019
I do not entirely understand what you are doing.
Consider using your array as a persistent (link) variable.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!