MATLAB Object-Oriented Programming

(Joyce) #1

Behavior of Inherited Built-In Methods


In this section...
“Subclass double” on page 12-54
“Built-In Data Value Methods” on page 12-55
“Built-In Data Organization Methods” on page 12-56
“Built-In Indexing Methods” on page 12-57
“Built-In Concatenation Methods” on page 12-57

Subclass double


Most built-in functions used with built-in classes are actually methods of the built-in class.
For example, the double and single classes define several methods to perform
arithmetic operations, indexing, matrix operation, and so on. All these built-in class
methods work with subclasses of the built-in class.

Subclassing double enables your class to use features without implementing the
methods that a MATLAB built-in class defines.

The DocSimpleDouble class subclasses the built-in double class.

classdef DocSimpleDouble < double
methods
function obj = DocSimpleDouble(data)
if nargin == 0
data = 0;
end
obj = obj@double(data);
end
end
end

Create an instance of the class DocSimpleDouble.

sc = DocSimpleDouble(1:10)

sc =
1x10 DocSimpleDouble:
double data:
1 2 3 4 5 6 7 8 9 10

12 How to Build on Other Classes

Free download pdf