MATLAB Object-Oriented Programming

(Joyce) #1
Default Enumeration Member

The default member an enumeration class is the first enumeration member defined in the
enumeration block. For the WeekDays class, the default enumeration member is
WeekDays.Monday.

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

MATLAB allows assignment to any element of an array, even if the array variable does not
previously exist. To fill in unassigned array elements, MATLAB uses the default
enumeration member.

For example, assign a value to element 5 of an array, a:

clear a
a(5) = WeekDays.Tuesday;

MATLAB must initialize the values of array elements a(1:4) with the default
enumeration member. The result of the assignment to the fifth element of the array a is:

a

a =

Monday Monday Monday Monday Tuesday

See Also


Related Examples



  • “Operations on Enumerations” on page 14-19


14 Enumerations

Free download pdf