MATLAB Object-Oriented Programming

(Joyce) #1
Mixed Sets of Enumeration and char

If you pass both enumeration and char arguments to an enumeration class method, the
class attempts to convert the char to the class of the enumeration.

Determine if char vector is a member of the enumeration array.

teamMeetings = [WeekDays.Wednesday WeekDays.Friday];
ismember('Friday',teamMeetings)

ans =

1

Determine if the enumeration member is a member of the cell array of char vectors.

ismember(WeekDays.Friday,{'Wednesday','Friday'})

ans =

1

Enumeration Text Comparison Methods


Enumeration classes provide methods to compare enumeration members with char
vectors. One of the arguments to the string comparison method must be a char vector.
Comparing two enumeration members returns false.


  • strcmp — Compare enumeration members

  • strncmp — Compare first n characters of enumeration members

  • strcmpi — Case insensitive comparison of enumeration members

  • strncmpi — Case insensitive first n character comparison of enumeration members


Comparing Enumeration Member with char Vector

The string comparison methods can compare enumeration members and char vectors.

today = WeekDays.Tuesday;
strcmp(today,'Friday')

ans =

0

14 Enumerations

Free download pdf