persistent
Declares a list of variables as persistent. When a variable is declared as persistent, its value is retained after the function exits.
Syntax
persistent x
Inputs
- x
- A variable name to be declared as persistent.
Example
function b=foo()
persistent z;
if (isempty(z))
z=1;
else
z=z+1;
end
b=z;
end
foo
foo
ans =1
ans = 2