- #1
Somefantastik
- 230
- 0
Hello,
I am trying to figure out how to clear a variable inside a subroutine from a calling function. The variable in the subroutine acts as a persistent(MATLAB) or static(C), but once in so many calls I want it to be reset to empty as if the subroutine is being called for the first time.
I can do this in MATLAB by calling the subroutine in a for loop. On the kth run, clear functions, call subroutine. The subroutine is now called with persistent variables cleared:
function y = foo(a)
n = 6;
k = 3;
for ii = 1:n
Any help would be appreciated,
Candice
I am trying to figure out how to clear a variable inside a subroutine from a calling function. The variable in the subroutine acts as a persistent(MATLAB) or static(C), but once in so many calls I want it to be reset to empty as if the subroutine is being called for the first time.
I can do this in MATLAB by calling the subroutine in a for loop. On the kth run, clear functions, call subroutine. The subroutine is now called with persistent variables cleared:
function y = foo(a)
n = 6;
k = 3;
for ii = 1:n
if ii == k
x(ii) = subfoo(a)
endclear functions
endx(ii) = subfoo(a)
Any help would be appreciated,
Candice