MATLAB Object-Oriented Programming

(Joyce) #1

Operations on Enumerations


In this section...
“Operations Supported by Enumerations” on page 14-19
“Enumeration Class” on page 14-19
“Default Methods” on page 14-20
“Convert Enumeration Member to Characters” on page 14-20
“Convert Enumeration Array to Cell Array of char Vectors” on page 14-20
“Enumerations and char Vectors in Relational Operations” on page 14-21
“Enumerations in switch Statements” on page 14-22
“Enumeration Set Membership” on page 14-23
“Enumeration Text Comparison Methods” on page 14-24
“How to Get Information About Enumerations” on page 14-25
“Testing for an Enumeration” on page 14-25

Operations Supported by Enumerations


You can use logical, set membership, and string comparison operations on enumerations.
These operations also allow the use of enumeration in conditional statements, such as
switch and if statements. Converters enable you to use char vectors and cell arrays of
strings as enumerations.

Enumeration Class


The WeekDays class defines members that enumerate days of the week. This topic uses
the WeekDays class to illustrate how to perform operations on enumerations.

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

For information on defining enumerations, see “Define Enumeration Classes” on page 14-
5.

Operations on Enumerations
Free download pdf