enumeration
Lists the members of an enumeration class.
Category: Programming > Classes
Syntax
enumeration ClassName
Displays the enumeration members of the class.
m = enumeration('ClassName')
Returns the members as a column of enumeration objects.
[m, names] = enumeration('ClassName')
Also returns the member names as a cell array of character vectors.
Description
An enumeration class defines a fixed set of named values in an enumeration block of a classdef file, for example Red, Green, Blue. The enumeration function is how a program discovers that set at run time, for instance to fill a menu or to loop over all choices.
It is also the keyword that opens that block inside a classdef; the function and the keyword are unrelated otherwise.
Input arguments
ClassName- Name of a class defined with an
enumerationblock.
Output arguments
m- The enumeration members.
names- Names of the members, in the order they were declared.
Example
A class that does not exist
try
enumeration('NoSuchEnum')
catch
disp('no such class')
end
no such class
Notes
A script cannot declare an enumeration class, so the example only shows the failure path. With a class saved in its own file, [m, names] = enumeration('Color') returns the members and their names as in MATLAB. Built-in enumeration classes such as matlab.lang.OnOffSwitchState are not available.