You can use char vectors to represent specific enumeration members:
function c = Reminder2(day)
switch(day)
case 'Monday'
c = 'Department meeting at 10:00';
case 'Tuesday'
c = 'Meeting Free Day!';
case {'Wednesday' 'Friday'}
c = 'Team meeting at 2:00';
case 'Thursday'
c = 'Volleyball night';
end
end
Although you can use char vectors instead of specifying enumerations explicitly, MATLAB
must convert the char to an enumeration. Eliminate the need for this conversion if it is
not necessary.
Enumeration Set Membership
Enumeration classes provide methods to determine set membership.
- ismember — True for elements of an enumeration array if in a set
- setdiff — Set difference for enumeration arrays
- intersect — Set intersection for enumeration arrays
- setxor — Set exclusive-or for enumeration arrays
- union — Set union for enumeration arrays
Determine if today is a meeting day for your team. Create a set of enumeration members
corresponding to the days on which the team has meetings.
today = WeekDays.Tuesday;
teamMeetings = [WeekDays.Wednesday WeekDays.Friday];
Use ismember to determine if today is part of the teamMeetings set:
ismember(today,teamMeetings)
ans =
0
Operations on Enumerations