MATLAB: How to get a handle to a public method inside a class in MATLAB 7.8 (R2009a)

classhandleMATLABmethod

I have a class definition file that conatins methods of the class. I want to get the handle to a method inside this class.

Best Answer

Suppose you have class called 'class_a' defined as follows:
classdef class_a
methods
function display_message(obj) % public method
disp('Hello, there!')
end
function h = get_handle(obj) % return handle to method 'display_message'
h = @display_message;
end
end
end
To get a handle to the method 'display_message', execute the following code:
obj_a = class_a;
h = obj_a.get_handle;
h(obj_a);