MATLAB Object-Oriented Programming

(Joyce) #1

Subclasses of Built-In Types Without Properties


In this section...
“Specialized Numeric Types” on page 12-60
“A Class to Manage uint8 Data” on page 12-60
“Using the DocUint8 Class” on page 12-61

Specialized Numeric Types


Subclass built-in numeric types to create customized data types that inherit the
functionality of the built-in type. Add functionality to that provided by the superclass by
implementing class methods. Subclasses without properties store numeric data as the
superclass type. If your subclass design does not require properties to store other data,
the implementation is simpler because you do not need to define indexing and
concatenation methods.

For more information, see “Subclasses of MATLAB Built-In Types” on page 12-50.

A Class to Manage uint8 Data


This example shows a class derived from the built-in uint8 class. This class simplifies the
process of maintaining a collection of intensity image data defined by uint8 values. The
basic operations of the class include:


  • Capability to convert various classes of image data to uint8 to reduce object data
    storage.

  • A method to display the intensity images contained in the subclass objects.

  • Ability to use all the methods supported by uint8 data (for example, size, indexing,
    reshape, bitshift, cat, fft, arithmetic operators, and so on).


The class data are matrices of intensity image data stored in the superclass part of the
subclass object. This approach requires no properties.

The DocUint8 class stores the image data, which converts the data, if necessary:

classdef DocUint8 < uint8
methods
function obj = DocUint8(data)

12 How to Build on Other Classes

Free download pdf