Programming Previous page   Next Page

Designing User Classes in MATLAB

This section discusses how to approach the design of a class and describes the basic set of methods that should be included in a class.

The MATLAB Canonical Class

When you design a MATLAB class, you should include a standard set of methods that enable the class to behave in a consistent and logical way within the MATLAB environment. Depending on the nature of the class you are defining, you may not need to include all of these methods and you may include a number of other methods to realize the class's design goals.

This table lists the basic methods included in MATLAB classes.

Class Method
Description
class constructor
Creates an object of the class.
display
Called whenever MATLAB displays the contents of an object (e.g., when an expression is entered without terminating with a semicolon).
set and get
Accesses class properties.
subsref and subsasgn
Enables indexed reference and assignment for user objects.
end
Supports end syntax in indexing expressions using an object; e.g., A(1:end).
subsindex
Supports using an object in indexing expressions.
converters like double and char
Methods that convert an object to a MATLAB data type.

The following sections discuss the implementation of each type of method, as well as providing references to examples used in this chapter.


Previous page  Tips for C++ and Java Programmers The Class Constructor Method Next page

© 1994-2005 The MathWorks, Inc.