There is a handle class Foo
:
classdef Foo < handle
properties (SetAccess = public, GetAccess = public)
x
end
methods
function obj = foo(x)
% constructor
obj.x = x;
end
end
end
I create an object of Foo
:
data = [1 2];
foo = Foo(data); % handle object
I would like to create a reference (handle) variable a
that points to foo.x
. Is this possible in Matlab? For example, the following does not work:
a = foo.x; % here `a` equals [1 2], `a` is not a handle object
foo.x = [3 4]; % set property `x` to [3 4];
disp(a); % a still equals [1 2]
% even though the property `foo.x` has changed
% I want `a` to change when `foo.x` is changed.