MATLAB Object-Oriented Programming

(Joyce) #1

ans =


char


Enumerations and char Vectors in Relational Operations


Expression involving the relational operators, eq and ne, in which one operand is an
enumeration allow the other operand to be of type char. Before performing the
operation, MATLAB converts char vectors to scalar enumerations or cell arrays of char
vectors to enumeration arrays.


NoteEnumeration classes that derive from MATLAB built-in classes cannot substitute
char vectors for enumeration members.


today = WeekDays.Friday;
today == 'Friday'


ans =


1


Compare enumeration array to char vector:


wd = [WeekDays.Monday,WeekDays.Wednesday,WeekDays.Friday];
wd == 'Friday'


ans =


0 0 1


Compare enumeration array to cell array of char vectors:


cv = {'Monday','Wednesday','Friday'};
md = [WeekDays.Tuesday,WeekDays.Thursday,WeekDays.Friday];
md ~= cv


ans =


1 1 0


Test equality to implement if statements. The char vector Wednesday is equal to (==)
the enumeration member WeekDays.Wednesday:


Operations on Enumerations
Free download pdf