Main Content

La traducción de esta página está obsoleta. Haga clic aquí para ver la última versión en inglés.

Propiedades

Declaración de propiedades, atributos y métodos de acceso

Las propiedades contienen datos de objetos. Las clases definen las mismas propiedades para todo el objeto, pero cada objeto puede tener valores de datos únicos. Los atributos de las propiedades controlan qué funciones o métodos pueden acceder a la propiedad. Es posible definir funciones que se ejecuten cada vez que se definan o consulten valores de propiedades. Las propiedades pueden activar eventos cuando el código acceda a sus valores.

Funciones

expandir todo

propertiesClass property names
ispropTrue if property exists

Validación de atributos de valor numérico

mustBePositiveValidate that value is positive
mustBeNonpositiveValidate that value is nonpositive
mustBeNonnegativeValidate that value is nonnegative
mustBeNegativeValidate that value is negative
mustBeFiniteValidate that value is finite
mustBeNonNanValidate that value is not NaN
mustBeNonzeroValidate that value is nonzero
mustBeNonsparseValidate that value is nonsparse
mustBeRealValidate that value is real
mustBeIntegerValidate that value is integer
mustBeNonmissingValidate that value is not missing

Validación de la comparación

mustBeGreaterThanValidate that value is greater than another value
mustBeLessThanValidate that value is less than another value
mustBeGreaterThanOrEqualValidate that value is greater than or equal to another value
mustBeLessThanOrEqualValidate that value is less than or equal to another value

Validación del tipo de datos

mustBeAValidate that value comes from one of specified classes
mustBeNumericValidate that value is numeric
mustBeNumericOrLogicalValidate that value is numeric or logical
mustBeFloatValidate that value is floating-point array
mustBeTextValidate that value is string array, character vector, or cell array of character vectors
mustBeTextScalarValidate that value is single piece of text
mustBeNonzeroLengthTextValidate that value is text with nonzero length
mustBeUnderlyingTypeValidate that value has specified underlying type

Validación de tamaño

mustBeNonemptyValidate that value is nonempty
mustBeScalarOrEmptyValidate that value is scalar or empty
mustBeVectorValidate that value is vector

Validación de miembros y rango

mustBeMemberValidate that value is member of specified set
mustBeInRangeValidate that value is in the specified range

Texto con validación de significado especial

mustBeFileValidate that path refers to file
mustBeFolderValidate that input path refers to folder
mustBeValidVariableNameValidate that input name is valid variable name

Clases

dynamicpropsSuperclass for classes that support dynamic properties
meta.DynamicPropertyDescribe dynamic property of MATLAB object
event.DynamicPropertyEventEvent data for dynamic property events
meta.propertyDescribe property of MATLAB class
meta.Validation Describes property validation
meta.FixedDimension Fixed dimension in property size specification
meta.UnrestrictedDimension Unrestricted dimension in property size specification
meta.ArrayDimension Size information for property validation
matlab.lang.OnOffSwitchStateRepresent on and off states with logical values

Temas

Definir propiedades y establecer atributos

Ways to Use Properties

There are different kinds of properties and each serves a different purpose.

Property Syntax

When you define properties, you also specify property attributes that control certain aspects of the property’s behavior.

Property Attributes

Attributes control the behavior of properties.

Property Access List

Specify a list of classes that can access a property.

Mutable and Immutable Properties

You can control what code can set property values.

Property Definition

Classes can assign default values to properties and you can change these values during object construction or direct access to the properties.

Define Class Properties with Constant Values

Use a class with Constant 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.

Validación de propiedades

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.

Métodos de acceso a propiedades

Property Access Methods

Property access methods execute code when property values are referenced or assigned. Implementing these methods enables you to control what actions occur when values are set or queried.

Property Set Methods

Property set methods must follow specific syntax and execution rules.

Property Get Methods

Property get methods must follow specific syntax and execution rules.

Set and Get Methods for Dependent Properties

Dependent properties need access methods because these properties do not store values. Property access methods manage interactions with the dependent properties.

Propiedades dinámicas

Dynamic Properties — Adding Properties to an Instance

You can add instance data to an object derived from the dynamicprops 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 for PropertyAdded and PropertyRemoved events on dynamic properties.

Dynamic Properties and ConstructOnLoad

Use the ConstructOnLoad attribute to save and load dynamic properties.