Main Content
Properties
Property declaration, attributes, and access methods
Properties contain object data. Classes define the same properties for all objects, but each object can have unique data values. Property attributes control what functions or methods can access the property. You can define functions that execute whenever you set or query property values. Properties can trigger events when code accesses their values.
Functions
Classes
dynamicprops | Superclass for classes that support dynamic properties |
matlab.metadata.DynamicProperty | Describe dynamic property of MATLAB object |
event.DynamicPropertyEvent | Event data for dynamic property events |
matlab.metadata.Property | Describe property of MATLAB class |
matlab.metadata.Validation | Describes property validation |
matlab.metadata.FixedDimension | Fixed dimension in property size specification |
matlab.metadata.UnrestrictedDimension | Unrestricted dimension in property size specification |
matlab.metadata.ArrayDimension | Size information for property validation |
matlab.lang.OnOffSwitchState | Represent on and off states with logical values |
Topics
Define Properties and Set Attributes
- Ways to Use Properties
Class properties can be defined to satisfy different use cases. - Property Syntax
Define class properties using attributes and validators that control behavior. - Property Attributes
Attributes control the behavior of properties. - Mutable and Immutable Properties
You can control what code can set property values. - Initialize Property Values
Classes can assign default values to properties, and you can change these values during object construction. - Define Class Properties with Constant Values
Use a class withConstant
properties to define constant values. - Properties Containing Objects
Properties assigned objects as default values construct that object only once when the class is first loaded. Also, assignment to contained object properties behaves differently depending on whether the object is a handle or value.
Property Validation
- Validate Property Values
You can restrict property values to a size and class, and apply functions to validate assigned values. - Property Class and Size Validation
Define class and size requirements for a property. - Property Validation Functions
Property validation functions enable you to check the values being assigned to properties. - Metadata Interface to Property Validation
Programmatically determine the size, class, and validation functions that validate the values assigned to properties.
Property Access Methods
- Property Get and Set Methods
Property access methods execute code when property values are referenced or assigned. - Get and Set Methods for Dependent Properties
Define get and set access methods for dependent properties.
Dynamic Properties
- Dynamic Properties — Adding Properties to an Instance
You can add instance data to an object derived from thedynamicprops
class. - Set and Get Methods for Dynamic Properties
You can implement what are effectively access methods for dynamic properties. - Dynamic Property Events
You can define listeners forPropertyAdded
andPropertyRemoved
events on dynamic properties. - Dynamic Properties and ConstructOnLoad
Use theConstructOnLoad
attribute to save and load dynamic properties.