Classdef Block

How to Specify Attributes and Superclasses

The classdef block contains the class definition. The classdef line is where you specify:

  • Class attributes

  • Superclasses

The classdef block contains the properties, methods, and events subblocks.

Class Attribute Syntax

Class attributes modify class behavior in some way. Assign values to class attributes only when you want to change their default value.

No change to default attribute values:

classdef ClassName
   ...
end

One or more attribute values assigned:

classdef (attribute1 = value,...)
   ...
end

For example, the TextString class specifies that it cannot be used to derive subclasses:

classdef TextString (Sealed)
   ...
end

See Class Attributes for a list of attributes and a discussion of the behaviors they control.

Superclass Syntax

Derive a class from one or more other classes by specifying the superclasses on the classdef line:

classdef ClassName < SuperclassName
   ...
end

For example, the LinkedList class inherits from classes called Array and handle:

classdef LinkedList < Array & handle
   ...
end

Local Functions in Class File

You can define only one class per file. However, you can add local functions to a file containing the classdef block. Local functions are scoped to the classdef file and have access to private and protected class members.

classdef ClassName
   ...
end
function localFunction
   ...
end

Related Topics