MATLAB Object-Oriented Programming

(Joyce) #1

Refer to Enumerations


In this section...
“Instances of Enumeration Classes” on page 14-11
“Conversion of Characters to Enumerations” on page 14-13
“Enumeration Arrays” on page 14-15

Instances of Enumeration Classes


Enumeration members are instances of the enumeration class. You can assign
enumeration members to variables and form arrays of enumeration members. If an
enumeration class derives from a superclass, you can substitute an enumeration member
for an instance of the superclass.

The WeekDays class defines enumeration members for five days of the week.

classdef WeekDays
enumeration
Monday, Tuesday, Wednesday, Thursday, Friday
end
end

Create objects of the WeekDays class representing specific days.

today = WeekDays.Monday;
tomorrow = WeekDays.Tuesday;

The variables today and tomorrow are objects of the WeekDays class.

The PPM class defines three enumeration members. Each member has an associated
numeric value derived from the class superclass.

classdef PPM < double
enumeration
High (1000)
Medium (100)
Low (10)
end
end

Assign an enumeration member to a variable.

Refer to Enumerations
Free download pdf