This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Attribute Specification

Attribute Syntax

Attributes modify the behavior of classes and class components (properties, methods, and events). Attributes enable you to define useful behaviors without writing complicated code. For example, you can create a read-only property by setting its SetAccess attribute to private, but leaving its GetAccess attribute set to public:

properties (SetAccess = private)
   ScreenSize = getScreenSize

All class definition blocks (classdef, properties, methods, and events) support specific attributes. All attributes have default values. Specify attribute values only in cases where you want to change from the default value to another predefined value.

    Note:   Specify the value of a particular attribute only once in any component block.

Attribute Descriptions

For lists of supported attributes, see:

Attribute Values

When you specify attribute values, those values affect all the components defined within the defining block. For example, the following property definition blocks set the:

  • AccountBalance property SetObservable attribute to true

  • SSNumber and CreditCardNumber properties' Hidden attribute to true and SetAccess attribute to private.

Defining properties with different attribute settings requires multiple properties blocks.

properties (SetObservable = true) 
properties (SetAccess = private, Hidden = true)

Specified multiple attributes in a comma-separated list, as shown in the previous example.

When specifying class attributes, place the attribute list directly after the classdef keyword:

classdef (AttributeName = attributeValue) ClassName

Simpler Syntax for true/false Attributes

You can use a simpler syntax for attributes whose values are true or false — the attribute name alone implies true and adding the not operator (~) to the name implies false. For example:

methods (Static)

Is the same as:

methods (Static = true)

Use the not operator before an attribute name to define it as false:

methods (~Static) 

Is the same as:

methods (Static = false)

All attributes that take a logical value (that is, true or false) have a default value of false. Therefore, specify an attribute only if you want to set it to true.

Related Examples

Was this topic helpful?