| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Stateflow |
| Contents | Index |
| Learn more about Stateflow |
| On this page… |
|---|
Tasks for Defining Enumerated Data in a Chart |
To use enumerated data in a chart:
Define an enumerated data type in a file on the MATLAB path.
This data type is a MATLAB class definition. For details, see Object-Oriented Programming in the MATLAB documentation.
Add data of the enumerated type to a chart.
To define an enumerated data type:
Create a new file to store the data type definition.
In the MATLAB Command Window, select File > New > Class.
Define enumerated values in an enumeration section.
classdef(Enumeration) EnumTypeName < Simulink.IntEnumType
enumeration
EnumName(N)
...
end
endEnumTypeName 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
endThe 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.
For details, see Elements of an Enumerated Data Type Definition or Overriding Default Methods (Optional) in the Simulink User's Guide.
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.
To add enumerated data to a chart:
In the Stateflow Editor, select Add > Data and choose a scope other than Constant.
The Data properties dialog box appears.
In the General pane, 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 Defining an Enumerated Data Type in a File.)
Click Apply.
(Optional) In the Value Attributes pane, 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 Stateflow Chart.)
For example, BasicColors.Red is an identifier that uses prefixed notation. (See Prefixed Notation for Enumerated Values.)
Note If you leave this field empty, the default enumerated value applies — that is, the first value in the data type definition. To specify the default value explicitly, see Elements of an Enumerated Data Type Definition or Overriding Default Methods (Optional) in the Simulink User's Guide. |
Click OK.
![]() | Elements of an Enumerated Data Type Definition | Ensuring That Changes in Data Type Definition Take Effect | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2010- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |