MATLAB Object-Oriented Programming

(Joyce) #1

Prop1: 7
Prop2: '17-Feb-2015 15:19:34'


Copy a to b using the copy method inherited from matlab.mixin.Copyable:


b = copy(a)


b =


CopiedClass with properties:


Prop1: []
Prop2: '17-Feb-2015 15:19:34'


In the copy b, the value of Prop1 is not copied. The value of Prop2 is set to its default
value, which MATLAB determined when first loading the class. The timestamp does not
change.


Objects with Dynamic Properties


Subclasses of the dynamicprops class allow you to add properties to an object of the
class. When a class derived from dynamicprops is also a subclass of
matlab.mixin.Copyable, the default implementation of copyElement does not copy
dynamic properties. The default value of NonCopyable is true for dynamic properties.


The default implementation of copyElement honors the value of a dynamic property
NonCopyable attribute. If you want to allow copying of a dynamic property, set its
NonCopyable attribute to false. Copying a dynamic property copies the property value
and the values of the property attributes.


For example, this copy operation copies the dynamic property, DynoProp, because its
NonCopyable attribute is set to false. The object obj must be an instance of a class
that derives from both dynamicprops and matlab.mixin.Copyable:


obj = MyDynamicClass;
p = addprop(obj,'DynoProp');
p.NonCopyable = false;
obj2 = copy(obj);


See Also


matlab.mixin.Copyable


See Also
Free download pdf