MATLAB Object-Oriented Programming

(Joyce) #1

ret(kk) = true;
else
ret(kk) = false;
end
end
end
end
end
end


Use SwitchOnVer objects in switch statements:


% Create known versions of objects
ov1 = SwitchOnVer(1.0);
ov2 = SwitchOnVer(2.0);
ov3 = SwitchOnVer(3.0);
...


...
if isscalar(objIn)
switch(objIn)
case ov1
disp('This is version 1.0')
case ov2
disp('This is version 2.0')
case ov3
disp('This is version 3.0')
otherwise
disp('There is no version')
end
else
error('Input object must be scalar')
end


Enumerations in Switch Statements


MATLAB enables you to use enumerations in switch statements without requiring an
explicitly defined eq method for the enumeration class.


For example, the WeeklyPlanner class defines enumerations for five days of the week.
The switch/case statements in the todaySchedule static method dispatch on the
enumeration member corresponding to the current day of the week. The date and
datestr functions return a char vector with the name of the current day.


Objects In Conditional Statements
Free download pdf