|On this page…|
Create a new file to store the data type definition.
In the MATLAB Command Window, select Home > New > Class.
Define enumerated values in an enumeration section.
classdef(Enumeration) EnumTypeName < Simulink.IntEnumType enumeration EnumName(N) ... end end
EnumTypeName is a case-sensitive string that must be unique among data type names and workspace variable names. An enumerated type can define any number of values. Each enumerated value consists of a string EnumName and an integer N. Each EnumName must be unique within its type, but can also appear in other enumerated types.
For example, you can enter the following lines in the MATLAB Editor:
classdef(Enumeration) BasicColors < Simulink.IntEnumType enumeration Red(0) Yellow(1) Green(2) end end
The classdef section defines an integer-based enumerated data type with the name BasicColors and derives it from the built-in type Simulink.IntEnumType. The enumeration section is the set of values that this data type allows. The default value is the first one in the list, unless you specify otherwise in the next step.
(Optional) Customize the data type using a methods section.
Save this file on the MATLAB path.
The name of your file must match exactly the name of your data type. For example, the data type BasicColors must reside in a file named BasicColors.m.
Add data to your chart and select a scope other than Constant.
In the General pane of the Data properties dialog box, enter a name and data type for the enumerated data.
In the Name field, enter a name.
In the Type field, select Enum: <class name>.
Replace <class name> with the name of the data type that you defined in a file on the MATLAB path.
For example, you can enter Enum: BasicColors in the Type field. (See Define an Enumerated Data Type in a File.)
(Optional) Enter an initial value for the enumerated data.
In the Initial value field, enter a prefixed identifier that refers to an enumerated value for this data type. (For details, see Rules for Using Enumerated Data in a Chart.)
For example, BasicColors.Red is an identifier that uses prefixed notation. (See Prefixed Notation for Enumerated Values.)