MATLAB: Do I receive an error when creating a function handle to a class method in MATLAB 7.8 (R2009a)

classfunctionhandleMATLABmethod

I am defining two classes Class1 and Class2, as follows:
%CLASS1
classdef Class1 < handle
methods
function obj = Class1(obj)
obj.prop1 = Class2();
end
end
properties
prop1;
end
end
%CLASS2
classdef Class2 < handle
methods
function doNothing(obj)
disp('Ok');
end
end
end
When I create an object of Class1, its property ‘prop1’ is an object of Class2; allowing me to invoke the 'doNothing' method.
a = Class1;
a.prop1.doNothing;
This will print ‘Ok’ at the command prompt. But, when I try to create a function handle to this method, MATLAB is not able to interpret this command and throws an error when I use the function handle.
F_handle = @ a.prop1.doNothing;
F_handle();
However this works fine:
F_handle = @ ()a.prop1.doNothing;
F_handle();
b = Class2;
F_handle2 = @b.doNothing

Best Answer

The syntax F_handle = @obj.property.method is not supported in MATLAB 7.8 (R2009a). You need to use the anonymous function syntax instead:
F_handle = @ ()a.prop1.doNothing;