Work with Members of a .NET Enumeration
To display the member names of an enumeration, use the MATLAB®
enumeration function. For example, to list the member names of the
System.DayOfWeek enumeration, type:
enumeration('System.DayOfWeek')
Enumeration members for class 'System.DayOfWeek':
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
SaturdayYou cannot use the enumeration command to return arrays of .NET
enumeration objects. You can read the names and values of the enumeration into arrays,
using the System.Enum methods GetNames,
GetValues, and GetType.
For example, to create arrays allNames and
allValues for the System.DayOfWeek
enumeration, type:
myDay = System.DayOfWeek; allNames = System.Enum.GetNames(myDay.GetType); allValues = System.Enum.GetValues(myDay.GetType);
The class of the names array is System.String, while the class of
the values array is the enumeration type System.DayOfWeek.
whos all*
Name Size Bytes Class allNames 1x1 112 System.String[] allValues 1x1 112 System.DayOfWeek[]
Although the types are different, the information MATLAB displays is the same. For example, type:
allNames(1)
ans = Sunday
Type:
allValues(1)
ans = Sunday