Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

Class Attributes

Table of Class Attributes

All classes support the attributes listed in the following table. Attributes enable you to modify the behavior of class. Attribute values apply to the class defined within the classdef block.

Attribute Name

Class

Description

Hidden

logical

(default = false)

If true, this class does not appear in the output of MATLAB commands or tools that display class names.

InferiorClasses

cell

(default = {})

Use this attribute to establish a precedence relationship among classes. Specify a cell array of meta.class objects using the ? operator.

The built-in classes double, single, char, logical, int64, uint64, int32, uint32, int16, uint16, int8, uint8, cell, struct, and function_handle are always inferior to user-defined classes and do not show up in this list.

See Specifying Class Precedence

ConstructOnLoad

logical

(default = false)

If true, MATLAB calls the class constructor when loading an object from a MAT-file. Therefore, you must implement the constructor so it can be called with no arguments without producing an error.

See Calling Constructor When Loading

Sealed

logical

(default = false)

If true, this class can not be subclassed.

Specifying Attributes

Attributes are specified for class members in the classdef, properties, methods, and events definition blocks. The particular attribute setting applies to all members defined within that particular block. This means that, for example, you might use multiple properties definition blocks so you can apply different attribute setting to different properties.

Superclass Attributes Are Not Inherited

Class attributes are not inherited, so superclass attributes do not affect subclasses.

Attribute Syntax

Specify class attribute values in parentheses, separating each attribute name/attribute value pair with a comma. The attribute list always follows the classdef or class member key word, as shown below:

classdef (attribute-name = expression, ...) ClassName

   properties (attribute-name = expression, ...)
      ...
   end
   methods (attribute-name = expression, ...)
      ...
   end
   events (attribute-name = expression, ...)
      ...
   end
end

Evaluating Expressions in Attribute Assignments

The term expression in the statements above is used to mean any legal MATLAB expression that evaluates to a single array. The expression is evaluated when the class definition is first needed and the resulting value is treated as a constant.

The MATLAB language evaluates the expression in its own context and cannot reference variables or the class being defined. Attribute expressions can reference static methods and properties of other classes and use the MATLAB path context of the class at the time of definition. This means the expression cannot access variables in the MATLAB workspace, but can access any function and static method or property that is on your path at the time MATLAB evaluates the class definition.

For example, in the following classdef line, the Sealed attribute is set to logical true only if a certain directory is on the MATLAB path.

classdef (Sealed = isdir('myDir'))
  


Recommended Products

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