有一个句柄类Foo
:
classdef Foo < handle
properties (SetAccess = public, GetAccess = public)
x
end
methods
function obj = foo(x)
% constructor
obj.x = x;
end
end
end
我创建了一个对象Foo
:
data = [1 2];
foo = Foo(data); % handle object
我想创建一个指向. 这在 Matlab 中可能吗?例如,以下内容不起作用:a
foo.x
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.