To enhance the readability of a Stateflow® chart, use enumerated data. With enumerated data, you can:
Create a restricted set of values and refer to those values by name.
Group related values into separate data types.
Avoid defining a long list of constants.
Enumerated data is supported in Stateflow charts in Simulink® models. For more information, see Reference Values by Name by Using Enumerated Data.
To avoid name conflicts, the name of an enumerated data type cannot match the name of another data type or a variable in the MATLAB® base workspace.
To enable resolution of enumerated data types for Simulink models, the name of the MATLAB file that contains the type definition must match the name of the data type.
When you update an enumerated data type definition for an open model, the changes do not take effect immediately. To see the effects of updating a data type definition:
Save and close the model.
Delete all instances of the data type from the MATLAB base workspace. To find these instances, type
the command prompt.
Open the model and start simulation or generate code by using Simulink Coder™.
If you use nonprefixed identifiers to refer to enumerated values in a chart, ensure that each enumerated name belongs to a unique enumerated data type.
If an enumerated value uses the same identifier as a data object or a bus field, the
chart does not resolve the identifier correctly. For example, this diagram shows the
stages in which a chart tries to resolve the identifier
If you choose to set an initial value for enumerated data, you must use a prefixed
identifier in the Initial value field of the Property Inspector. For
BasicColors.Red is a valid identifier, but
Red is not. The initial value must evaluate to a valid MATLAB expression.
If you add prefixes to enumerated names in the generated code, you enhance readability and avoid name conflicts with global symbols. For details, see Use Enumerated Data in Generated Code (Simulink Coder).
For enumerated data, leave the Minimum and Maximum fields of the Property Inspector empty. The chart ignores any values that you enter in these fields.
Whether these fields appear in the Property Inspector depends on which Type field option you use to define enumerated data.
|Type Field Option||Appearance of the Minimum and Maximum Fields|
Because enumerated values are constants, assigning these values to constant data is redundant and unnecessary. If you try to assign enumerated values to constant data, an error appears.
mlNamespace Operator to Access Enumerated Data
ml operator does not support enumerated data.
Machine-parented data is not supported for enumerated types.