clear persistent variable in subfunctions
9 views (last 30 days)
i have a script which repeadetly calls a subfunction. In that subfunction i have a persistent variable that grows by 1 everytime its called.
after im done i want to reset the persistent variable inside the subfunction.
if isempty(a); a = 0; end
a = a+1
the output should be: 1-2-3-1
but it is 1-2-3-4, and when i run the script again it is 5-6-7-8.
I do NOT want to use:
I just want to clear the persistent varibale inside that specific funtion.
I reckon i could pass a flag into fun1 to initialize it, but i believe there must be a better way to do this.