The answer is to get a function descriptor like @Pablo .
Please note that your class must be obtained from the handle class in order for it to work correctly (so that the object is passed by reference).
Consider the following example:
hello.m
classdef hello < handle properties name = ''; end methods function this = hello() this.name = 'world'; end function say(this) fprintf('Hello %s!\n', this.name); end end end
Now we get the handle to the member function and use it:
obj = hello(); %# create object f = @obj.say; %# get handle to function obj.name = 'there'; %# change object state obj.say() f()
Exit:
Hello there! Hello there!
However, if we define it as a Value Class (change the first line to classdef hello ), the result will be different:
Hello there! Hello world!
Amro
source share