MATLAB Object-Oriented Programming

(Joyce) #1
level = PPM.High;

When you substitute enumeration members for instances of the superclass, MATLAB
coerces the enumeration member to the superclass. For example, add an enumeration
member of the PPM class with a numeric values

levelNew = level + 100

levelNew =

1100

The result is of class double.

whos

Name Size Bytes Class Attributes

level 1x1 108 PPM
levelNew 1x1 8 double

You can substitute superclass values for enumeration members when the values
correspond. For example, pass one of the numeric values defined in the enumeration class
to the PPMSwitch function.

function PPMSwitch(ppm)
switch ppm
case PPM.Low
disp Low
case PPM.Medium
disp Medium
case PPM.High
disp High
end
end

PPMSwitch(100)

Medium

You can also use an enumeration member directly:

PPMSwitch(PPM.Medium)

Medium

14 Enumerations

Free download pdf