How do I get a handle to a public method inside a class in MATLAB 7.8 (R2009a)?

1 view (last 30 days)
I have a class definition file that conatins methods of the class. I want to get the handle to a method inside this class.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 20 Jul 2009
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);

More Answers (0)

Categories

Find more on Construct and Work with Object Arrays in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!