【发布时间】:2010-09-17 13:32:13
【问题描述】:
我正在尝试创建一个带有成员变量的 MATLAB 类,该成员变量由于方法调用而被更新,但是当我尝试更改类中的属性时(显然,根据我从 MATLAB 的内存管理中了解到的)创建对象的副本,然后对其进行修改,保持原始对象的属性不变。
classdef testprop
properties
numRequests=0;
end
methods
function Request(this, val)
disp(val);
this.numRequests=this.numRequests+1;
end
end
end
.
>> a=testprop;
>> a.Request(9);
>> a.Request(5);
>> a.numRequests
ans = 0
【问题讨论】:
-
编辑了我的答案以考虑您的编辑。
-
哦,啊...我仍在使用 R2006b,我猜他们终于在 MATLAB 中制作了“真正的”类(过去很痛苦)
标签: matlab oop properties matlab-class