Properties - MATLAB & Simulink (original) (raw)
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
properties | Class property names |
---|---|
isprop | Determine if property is defined by object |
Numeric Value Attribute Validation
mustBePositive | Validate that value is positive |
---|---|
mustBeNonpositive | Validate that value is nonpositive |
mustBeNonnegative | Validate that value is nonnegative |
mustBeNegative | Validate that value is negative |
mustBeFinite | Validate that value is finite |
mustBeNonNan | Validate that input contains NaN |
mustBeNonzero | Validate that value is nonzero |
mustBeNonsparse | Validate that value is nonsparse |
mustBeReal | Validate that value is real |
mustBeInteger | Validate that value is integer |
mustBeNonmissing | Validate that input does not contain missing values (Since R2020b) |
Comparison Validation
mustBeGreaterThan | Validate that value is greater than another value |
---|---|
mustBeLessThan | Validate that value is less than another value |
mustBeGreaterThanOrEqual | Validate that value is greater than or equal to another value |
mustBeLessThanOrEqual | Validate that value is less than or equal to another value |
Member and Range Validation
mustBeMember | Validate that value is member of specified set |
---|---|
mustBeBetween | Validate that all elements are within specified range (Since R2025a) |
Data Type Validation
mustBeA | Validate that value comes from one of specified classes (Since R2020b) |
---|---|
mustBeNumeric | Validate that value is numeric |
mustBeNumericOrLogical | Validate that value is numeric or logical |
mustBeFloat | Validate that value is floating-point array (Since R2020b) |
mustBeText | Validate that value is string array, character vector, or cell array of character vectors (Since R2020b) |
mustBeTextScalar | Validate that value is single piece of text (Since R2020b) |
mustBeNonzeroLengthText | Validate that value is text with nonzero length (Since R2020b) |
mustBeUnderlyingType | Validate that value has specified underlying type (Since R2020b) |
Size Validation
mustBeNonempty | Validate that value is nonempty |
---|---|
mustBeScalarOrEmpty | Validate that value is scalar or empty (Since R2020b) |
mustBeVector | Validate that value is vector (Since R2020b) |
Text with Special Meaning Validation
mustBeFile | Validate that path refers to file (Since R2020b) |
---|---|
mustBeFolder | Validate that input path refers to folder (Since R2020b) |
mustBeValidVariableName | Validate that input name is valid variable name (Since R2020b) |
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.