I follow the example in the documentation regarding the dependent attributes:
The class is defined as:
classdef TensileData properties Material SampleNumber Stress Strain end properties (Dependent) Modulus end methods function td = TensileData(material,samplenum,stress,strain) if nargin > 0 td.Material = material; td.SampleNumber = samplenum; td.Stress = stress; td.Strain = strain; end end function m = get.Modulus(obj) ind = find(obj.Strain > 0); m = mean(obj.Stress(ind)./obj.Strain(ind)); end end end
When I create an object of this class:
td = TensileData('carbon steel',1,[2e4 4e4 6e4 8e4],[.12 .20 .31 .40])
MATLAB shows me that the 'Modulus' is being calculated:
TensileData with properties: Material: 'carbon steel' SampleNumber: 1 Stress: [20000 40000 60000 80000] Strain: [0.1200 0.2000 0.3100 0.4000] Modulus: 1.9005e+05
However, the documentation says that the dependent attributes get method determines the property value when the property is queried. The dependent attributes are not supposed to be calculated upon creation of the object.
Best Answer