Dav*_*e_L 4 oop matlab matlab-class
如果我在MATLAB中制作以下玩具类:
classdef testIt
properties
a
b
c
end
methods
function obj = testIt
obj.a = 1;
obj.b = 2;
end
function obj = set.a(obj,a)
obj.a = a;
end
function obj = set.b(obj,b)
obj.b = b;
end
function obj = addup(obj)
obj.c = obj.a + obj.b;
end
end
end
Run Code Online (Sandbox Code Playgroud)
然后实例化并调用addup方法:
>> aTest = testIt
Properties:
a: 1
b: 2
c: []
>> aTest.addup
Properties:
a: 1
b: 2
c: 3
>> aTest
Properties:
a: 1
b: 2
c: []
Run Code Online (Sandbox Code Playgroud)
该物业c尚未创建.相反,我需要使用语法:
>> aTest = aTest.addup
>> aTest
Properties:
a: 1
b: 2
c: 3
Run Code Online (Sandbox Code Playgroud)
任何人都可以向我解释为什么这是必要的吗?