- When MATLAB copies a value object (any object that is not a handle), MATLAB does
not call the set or get method when copying property values from one object to
another. - Any assignment made to a property value that is the same as the current value when
the property’s AbortSet attribute is true. See “Assignment When Property Value Is
Unchanged” on page 11-44 for more information on this attribute.
Setting Property Value in Constructor
Setting a property value in the constructor causes the property set method to be called.
For example, the PropertySetMethod class defines a property set method for the Prop1
property.
classdef PropertySetMethod
properties
Prop1 = "Default String"
end
methods
function obj = PropertySetMethod( str )
if nargin > 0
obj.Prop1 = str;
end
end
function obj = set.Prop1(obj,str)
obj.Prop1 = str;
fprintf( 'set.Prop1 method called. Prop1 = %s\n', obj.Prop1 );
end
end
end
If you call the class constructor with no input arguments, MATLAB does not call the
set.Prop1 method.
>> o = PropertySetMethod
o =
PropertySetMethod with properties:
Prop1: "Default String"
8 Properties — Storing Class Data