matlab.metadata.Property Class
Namespace: matlab.metadata
Superclasses: matlab.metadata.MetaData
Description
The matlab.metadata.Property class provides information about the
properties of MATLAB® classes. Properties of the matlab.metadata.Property class contain
the values of property attributes and other information that is specified syntactically in the
class definition. All properties are read-only.
The matlab.metadata.Property class is a handle class.
Class Attributes
Abstract | true |
ConstructOnLoad | true |
For information on class attributes, see Class Attributes.
Creation
You cannot instantiate a matlab.metadata.Property object directly. Obtain a
matlab.metadata.Property object from the PropertyList
property of matlab.metadata.Class, which contains an array of
matlab.metadata.Property objects, one for each class property. For example,
replace ClassName with the name of the class whose properties you
want to query:
mco = ?ClassName; plist = mco.PropertyList; mp = plist(1); % matlab.metadata.Property for first property in list
Use the metaclass function to obtain a
matlab.metadata.Class object from a class instance:
mco = metaclass(obj);
Properties
Property name, returned as a character vector. The Name
property of matlab.metadata.Property corresponds to the name of the
associated property defined by the class.
Short description of the property, returned as a character vector. For user-defined classes, the text for this property comes from code comments for the property definition. If there are no comments, the property returns an empty character vector. For more information on how to include help text for your class properties, see Custom Help Text.
Detailed description of the property, specified as a character vector. For user-defined classes, the text for this property comes from code comments for the property definition. If there are no comments, the property returns an empty character vector. For more information on how to include help text for your class properties, see Custom Help Text.
Value of property attribute GetAccess, returned as:
public— unrestricted accessprotected— access from class or subclassesprivate— access by class members only (not from subclasses)List of classes that have read access to this property, specified as:
A single
matlab.metadata.Classobject.A cell array of
matlab.metadata.Classobjects. An empty cell array,{}, is the same asprivateaccess.
For more information, see Class Members Access.
Value of property attribute SetAccess, returned as:
public— unrestricted accessprotected— access from class or subclassesprivate— access by class members only (not from subclasses)immutable— property can only be set by constructor. For more information, see Mutable and Immutable Properties.List of classes that have write access to this property, specified as:
A single
matlab.metadata.Classobject.A cell array of
matlab.metadata.Classobjects. An empty cell array,{}, is the same asprivateaccess.
For more information, see Class Members Access.
Value of property attribute Dependent, returned as logical
true or false. If false (the
default), the property value is stored in the object. If true, the
property value is not stored in the object, and the set and get methods cannot access
the property by indexing into the object using the property name. Dependent properties
must define access methods. For more information, see Get and Set Methods for Dependent Properties.
Value of property attribute Constant, returned as logical
true or false. If true, this
property has the same value in all instances of the class. For more information, see
Define Class Properties with Constant Values.
Value of property attribute Abstract, returned as logical
true or false. If true, the
property has no implementation and the class is abstract. For more information, see
Abstract Classes and Class Members.
Value of property attribute Transient, returned as logical
true or false. If true, the
property value is not saved when the object is saved to a MAT-file. For more information
about saving objects, see Default Save and Load Process for Objects.
Value of property attribute Hidden, returned as logical
true or false. Hidden
determines if the property is shown in a property list (as a result of a call to
properties, for example). Hidden properties
are not shown in the default object display.
Value of property attribute GetObservable, returned as logical
true or false. If true, and
it is a handle class property, then you can create listeners that execute when the
property value is queried. MATLAB calls the listeners whenever property values are queried. For more
information, see Property-Set and Query Events.
Value of property attribute SetObservable, returned as logical
true or false. If true, and
it is a handle class property, then you can create listeners that execute when the
property value is set. MATLAB calls the listeners whenever property values are modified. For more
information, see Property-Set and Query Events.
Value of property attribute AbortSet, returned as logical
true or false. If true, then
setting a property value is aborted if the new value is the same as the current value.
If the property belongs to a handle class, setting AbortSet to
true prevents the triggering of property PreSet
and PostSet events.
Value of property attribute NonCopyable, returned as logical
true or false. If false, the
property value is copied when the object is copied (handle class only). By default, copying a handle object copies the concrete
properties of that object. For more information, see Exclude Properties from Copy.
Since R2024b
Value of property attribute WeakReference, returned as logical
true or false. If true, the
property value is a weak reference to a handle object. Weak references to an object do
not prevent that object from being deleted. For more information, see Weak References.
Value of property attribute PartialMatchPriority, returned as a
numeric value. Use with subclasses of matlab.mixin.SetGet to define the relative priority of partial property name
matches used in set and get method arguments. The default value is 1. Greater values
assign lower priorities. For more information, see Set Priority for Matching Partial Property Names.
Property get method, returned as a function handle of the get method associated with this property or an empty value. The value is empty if there is no get method specified in the class definition. For more information, see Property Get and Set Methods.
Property set method, returned as a function handle of the set method associated with this property or an empty value. The value is empty if there is no set method specified in the class definition. For more information, see Property Get and Set Methods
Indicates if the property has a default value, returned as logical
true or false. If true, the
property defines a default value in the class definition. Test
HasDefault before querying the DefaultValue
property to avoid a MATLAB:class:NoDefaultDefined error.
Default value specified in the class definition. Abstract, dependent, and dynamic properties cannot specify default values.
If there is no default value in the class definition, MATLAB does not display the DefaultValue property. Test
HasDefault before querying the DefaultValue
property to avoid a MATLAB:class:NoDefaultDefined error.
Validation defined for the property, returned as a
matlab.metadata.PropertyValidation object. This property contains a
matlab.metadata.Validation object describing the validation defined by this
property. If the property does not define validation, this property contains an empty
matlab.metadata.PropertyValidation object.
Class that defines the property, returned as a matlab.metadata.Class
object. The matlab.metadata.Class object represents the class that
defines this property, which can be a superclass.
Events
| Event Name | Trigger | Event Data | Event Attributes |
|---|---|---|---|
PreGet | Event occurs just before the property value is queried. | event.PropertyEvent |
|
PostGet | Event occurs just after the property value has been queried. | event.PropertyEvent |
|
PreSet | Event occurs just before the property value is changed. | event.PropertyEvent |
|
PostSet | Event occurs just after the property value has been changed. | event.PropertyEvent |
|
Examples
Use matlab.metadata.Property to get information about
a class property of the IntrospectionExample class.
classdef IntrospectionExample % IntrospectionExample Performs basic functions on two numbers % This class can return the sum and product of its two properties. properties % a First property % First of two numeric properties a {mustBeNumeric} = 0 % b Second property % Second of two numeric properties b {mustBeNumeric} = 0 end methods function sum = addNumbers(obj) % addNumbers Sum the properties % Finds the sum of properties a and b. sum = obj.a + obj.b; end function prod = multNumbers(obj) % multNumbers Multiply the properties % Finds the product of properties a and b. prod = obj.a*obj.b; end end end
Create a metaclass instance for IntrospectionExample. Access the
first property in the PropertyList of mc to get a
matlab.metadata.Property object.
mc = ?IntrospectionExample; mc.PropertyList(1)
ans =
Property with properties:
Name: 'a'
Description: 'First property'
DetailedDescription: 'First of two numeric properties'
GetAccess: 'public'
SetAccess: 'public'
Dependent: 0
Constant: 0
Abstract: 0
Transient: 0
Hidden: 0
GetObservable: 0
SetObservable: 0
AbortSet: 0
NonCopyable: 0
WeakHandle: 0
PartialMatchPriority: 1
HasDefault: 1
DefaultValue: 0
GetMethod: []
SetMethod: []
Validation: [1×1 matlab.metadata.PropertyValidation]
DefiningClass: [1×1 matlab.metadata.Class]
Check what validation the class performs on the property value. Property
a has no class or size restrictions, but it must satisfy the
mustBeNumeric validation function.
mc.PropertyList(1).Validation
ans =
PropertyValidation with properties:
Class: [0×0 matlab.metadata.Class]
Size: [1×0 matlab.metadata.ArrayDimension]
ValidatorFunctions: {@mustBeNumeric}
Version History
Introduced in R2008aThe class contains a new property, WeakReference. If
WeakReference is true, the property value is a
weak reference to a handle object. Weak references to an object do not prevent that object
from being deleted. For more information, see Weak References.
The namespace and class name of meta.property have been changed to
matlab.metadata.Property. The behavior remains the same.
MATLAB will continue to recognize the old metaclass names in most contexts. However,
code that relies on string comparisons to identify metaclasses might need to be updated to
continue to work as expected. For example, if mObj in the example below is
a matlab.metadata.Property instance, the code under the
case statement for 'meta.property' does not execute
because class(mObj) returns
'matlab.metadata.Property'.
switch class(mObj) case 'meta.property' % code to execute if mObj is a meta.property instance ... end
To ensure this code continues to work as intended, use an if
statement with isa. The isa command recognizes both
the old and new names of the
class.
if isa(mObj,'meta.property') % code to execute if mObj is a matlab.metadata.Property instance else ... end
'meta.property' to
'matlab.metadata.Property'. However, continue to use the old name if
your code needs to run on versions of MATLAB before R2024a.For user-defined classes with appropriately placed code comments, the
Description and DetailedDescription properties
are populated with text pulled from those comments. For more information on how to use code
comments to store custom help text for user-defined classes, see Custom Help Text.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)