これは「従属」プロパティと呼ばれます。派生プロパティを使用して、クラスの簡単な例は以下の通りです:定義されたこのクラスでは
classdef dependent_properties_example < handle %Note: Deriving from handle is not required for this example. It's just how I always use classes.
properties (Dependent = true, SetAccess = private)
derivedProp
end
properties (SetAccess = public, GetAccess = public)
normalProp1 = 0;
normalProp2 = 0;
end
methods
function out = get.derivedProp(self)
out = self.normalProp1 + self.normalProp2;
end
end
end
は、我々は今、実行することができます。
>> x = dependent_properties_example;
>> x.normalProp1 = 3;
>> x.normalProp2 = 10;
>> x
x =
dependent_properties_example handle
Properties:
derivedProp: 13
normalProp1: 3
normalProp2: 10
「は、所望の機能をプロパティ関数/デコレータの場合と同じですPythonで。 あなたはPythonを使用するように思えます。 –
@SlaterTyranus私はできることを望む。 – Dave