MATLAB: How to clear persistent variables from a function using only its handle

clear persistent variablesfunction handlesMATLABpersistent variables

For example, say I have a simple function, test1,
function test1 = test1(x,y)
persistent k
if isempty(k), k = sum(y); end
test1 = k*x*y;
which I call from another function, test0, within which I want to clear the persistent variable, k, in test1, for example,
function test0 = test0(x,y,fn)
clear fn
for i = 1:length(x)
test0 = fn(x(i),y);
end
using
test0(1,2,@test1)
But, of course, it doesn't work, with error
Reference to a cleared variable fn.
Error in test0 (line 4)
test0 = fn(x(i),y);
because the line
clear fn
doesn't do the job, for obvious reasons, but I don't know how to fix this.
Thanks in advance for your help.

Best Answer

Easy:
clear(func2str(yourfunctionhandle))
Note that from a design perspective, you'd be better off with a class rather than a function that holds state, particularly if that state is controlled from different places as you're trying to do.