MATLAB User-Defined Classes

A MATLAB class definition is a template whose purpose is to provide a description of all the elements that are common to all instances of the class. Class members are the properties, methods, and events that define the class.

MATLAB classes are defined in code blocks, with sub-blocks delineating the definitions of various class members. See classdef Syntax for details on the classdef block.

Attributes for Class Members

Attributes modify the behavior of classes and the members defined in the class-definition block. For example, you can specify that methods are static or that properties are abstract, and so on. The following sections describe these attributes:

  • Class Attributes
  • Method Attributes
  • Property Attributes
  • Event Attributes

Class definitions can provide information, such as inheritance relationships or the names of class members without actually constructing the class. See Working with Meta-Classes.

[important]See Specifying Attributes for more on attribute syntax.[/important]

Kinds of Classes

There are two kinds of MATLAB classes—handle and value classes.

  • Handle classes create objects that reference the data contained. Copies refer to the same data.
  • Value classes make copies of the data whenever the object is copied or passed to a function. MATLAB numeric types are value classes.

See Comparing Handle and Value Classes for a more complete discussion.

Constructing Objects

For information on class constructors, see Class Constructor Methods

For information on creating arrays of objects, see Creating Object Arrays

Creating Class Hierarchies

For more information on how to define class hierarchies, see Building on Other Classes.