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.
Numeric Value Attribute Validation
|Validate that value is positive
|Validate that value is nonpositive
|Validate that value is nonnegative
|Validate that value is negative
|Validate that value is finite
|Validate that value is not NaN
|Validate that value is nonzero
|Validate that value is nonsparse
|Validate that value is real
|Validate that value is integer
|Validate that value is not missing (Since R2020b)
|Validate that value is greater than another value
|Validate that value is less than another value
|Validate that value is greater than or equal to another value
|Validate that value is less than or equal to another value
Data Type Validation
|Validate that value comes from one of specified classes (Since R2020b)
|Validate that value is numeric
|Validate that value is numeric or logical
|Validate that value is floating-point array (Since R2020b)
|Validate that value is string array, character vector, or cell array of character vectors (Since R2020b)
|Validate that value is single piece of text (Since R2020b)
|Validate that value is text with nonzero length (Since R2020b)
|Validate that value has specified underlying type (Since R2020b)
|Validate that value is nonempty
|Validate that value is scalar or empty (Since R2020b)
|Validate that value is vector (Since R2020b)
Member and Range Validation
|Validate that value is member of specified set
|Validate that value is in the specified range (Since R2020b)
Text with Special Meaning Validation
|Superclass for classes that support dynamic properties
|Describe dynamic property of MATLAB object
|Event data for dynamic property events
|Describe property of MATLAB class
|Describes property validation
|Fixed dimension in property size specification
|Unrestricted dimension in property size specification
|Size information for property validation
|Represent on and off states with logical values
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 with
Constantproperties 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.
- 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
- Dynamic Properties — Adding Properties to an Instance
You can add instance data to an object derived from the
- 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 for
PropertyRemovedevents on dynamic properties.
- Dynamic Properties and ConstructOnLoad
ConstructOnLoadattribute to save and load dynamic properties.