Built-in types represent fundamental kinds of data such as numeric
arrays, logical arrays, and character arrays. Other built-in types
contain data belonging to these fundamental types and other classes.
can contain instances of any class.
Built-in types define methods that perform operations on objects
of these classes. For example, you can perform operations on numeric
arrays, such as, sorting, rounding values, and element-wise and matrix
multiplication. You can create an object of class
an assignment statement, indexing expressions, or using converter
See Fundamental MATLAB Classes for more information on MATLAB® built-in classes.
Note: It is an error to define a class that has the same name as a built-in class.
You cannot subclass the following built-in MATLAB classes:
You cannot subclass any class that has its
true. To determine if the class is
query the class metadata:
mc = ?ClassName; mc.Sealed
A value of
0 indicates that the class is
Sealed and can be subclasses.
Subclass a built-in type to extend the operations that you can perform on a particular class of data. For example, when you want to:
Define unique operations to perform on class data.
Be able to use methods of the built-in class and other
built-in functions directly with objects of the subclass. For example,
you do not need to reimplement all the mathematical operators if you
derived from a class such as
double that defines
Consider a class that defines enumerations. It can derive from
an integer class and inherit methods that enable you to compare and
sort values. For example, integer classes like
all the relational methods (
To see a list of functions that the subclass has inherited as
methods, use the
Generally, you can use an object of the subclass with any:
Functions that normally accept input arguments of the same class as the superclass.
When you define a subclass of a built-in class, the subclass inherits all the methods defined by that built-in class. MATLAB also provides additional methods to subclasses of built-in classes that override several built-in functions.
Built-in functions and methods that work on built-in classes can behave differently when called with subclasses of built-in classes. Their behavior depends on which function you are using and whether your subclass defines properties.
When you call an inherited method on a subclass of a built-in class, the result depends on the nature of the operation performed by the method. The behaviors of these methods fit into several categories.
Operations on data values return objects of the superclass.
For example, if you subclass
double and perform
addition on two subclass objects, MATLAB adds the numeric values
and returns a value of class
Operations on the orientation or structure of the
data return objects of the subclass. Methods that perform these kinds
of operations include,
and so on.
Converting a subclass object to a built-in class returns
an object of the specified class. Functions such as
with subclass objects the same as they work with built-in objects.
Comparing objects or testing for inclusion in a specific
set returns logical or built-in objects, depending on the function.
Functions such as
with subclass objects the same as they work with superclass objects.
Indexing expressions return objects of the subclass. If the subclass defines properties, then default indexing no longer works. The subclass must define its own indexing methods.
Concatenation returns an object of the subclass. If the subclass defines properties, then default concatenation no longer works and the subclass must define its own concatenation methods.
To list the built-in functions that work with a subclass of
a built-in class, use the
When a subclass of a built-in class defines properties, MATLAB no longer supports indexing and concatenation operations. MATLAB cannot use the built-in functions normally called for these operations because subclass properties can contain any data.
The subclass must define what indexing and concatenation mean for a class with properties. If your subclass needs indexing and concatenation functionality, then the subclass must implement the appropriate methods.
To support indexing operations, the subclass must implement these methods:
Implement dot notation and indexed assignments
Implement dot notation and indexed references
Implement object as index value
To support concatenation, the subclass must implement the following methods: