MATLAB Object-Oriented Programming

(Joyce) #1
d = Days;
d.Today = WeekDays.Tuesday;

d =

Days with properties:

Today: Tuesday

Representing Enumeration Members with char Vectors

The automatic conversion feature enables users of the Days class to assign values to the
Today property as either enumeration members, char vectors, or string scalars. The
Today property is restricted to members of the WeekDays enumeration class. Therefore,
you can assign a char vector that represents a member of the WeekDays class.

d = Days;
d.Today = 'Tuesday';

Also, you can use a string scalar:

d = Days;
d.Today = "Tuesday";

For more information on restricting property values, see “Validate Property Values” on
page 8-24 and “Property Class and Size Validation” on page 8-31.

14 Enumerations

Free download pdf