| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
| On this page… |
|---|
For a quick reference to all attributes, see Attribute Tables.
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 (the default):
properties (SetAccess = private) ScreenSize = getScreenSize; end
All class definition blocks (classdef, properties, methods, and events) support specific attributes and all attributes have default values. Specify attribute values only in cases where you want to change from the default value to another predefined value.
For lists of supported attributes, see:
When you specify attribute values, these values affect all the components defined within the definition 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) AccountBalance end properties (SetAccess = private, Hidden = true) SSNumber CreditCardNumber end
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 (Sealed = true) myclass ... end
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) ... end
is the same as:
methods (Static = true) ... end
Use the not operator before an attribute name to define it as false:
methods (~Static) ... end
is the same as:
methods (Static = false) ... end
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.
![]() | Events and Listeners | A Class Code Listing | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |