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.
An enumerated data type is a finite collection of enumerated values consisting of a name and an underlying integer value. For example, this chart uses enumerated data to refer to a set of colors.
The enumerated data
output is restricted to a finite set of values.
You can refer to these values by their names:
|Enumerated Value||Name||Integer Value|
This MATLAB® file defines the enumerated data type
referenced by the
classdef BasicColors < Simulink.IntEnumType enumeration Red(0) Yellow(1) Green(2) end end
An enumerated data type does not function as a numeric type despite the existence of the underlying integer values. You cannot use enumerated values directly in a mathematical computation. You can use enumerated data to control chart behavior based on assignments and comparisons. To assign or compare enumerated data, use the operations listed in this table.
In a chart that uses C as the action language, you can compare enumerated data with different data types. Before the comparison, the chart casts the enumerated data to their underlying integer values.
Charts that use MATLAB as the action language cannot compare enumerated data with different data types.
To refer to an enumerated value, use prefixed or nonprefixed identifiers.
To prevent name conflicts when referring to enumerated values in Stateflow charts, you can use prefixed identifiers of the form
Type is an enumerated data type and
Name is an enumerated value name. For example, suppose that
you define three data types (
Code) that contain the enumerated name
using prefixed notation, you can distinguish
To minimize identifier length when referring to unique enumerated values, you can use
nonprefixed enumerated value names. For example, suppose that the enumerated name
Red belongs only to the data type
Colors. You can
then refer to this value with the nonprefixed identifier
If your chart uses data types that contain identical enumerated names (such as
Temp.Red), use prefixed identifiers
to prevent name conflicts.
Use enumerated data at these levels of the Stateflow hierarchy:
Use enumerated data as arguments for:
Condition and transition actions
Vector and matrix indexing
Truth Table blocks and truth table functions
If you have Simulink Coder™ installed, you can use enumerated data for simulation and code generation.