MATLAB: Manipulating an anonymous function

anonymous functionsfunction handleMATLAB

I have a handle class myClass which has a property myFunc that is a function handle which I define with an anonymous function, e.g.
myClass.myFunc = @(x) 2*x
Is it possible to use myFunc to redefine itself? I tried
myClass.myFunc = @(x) -myClass.myFunc(x)
but trying to evaluate this led to a max recursion error. My function is defined inside of a class method using a local variable like:
myClass.myFunc = @(x) localVar*x
Otherwise, I would consider using func2str, but that doesn't help because it produces the expression involving localVar which is no longer defined. Right now, I am using
myClass.myOtherFunc = @(x) -myClass.myFunc(x)
but I'd prefer not to have to create a separate property just for this.

Best Answer

tmp = myClass.myFunc;
myClass.myFunc = @(x) ~tmp(x);