Main Content

Use State Hierarchy to Design Multilevel State Complexity

To manage multilevel state complexity, use hierarchy in your Stateflow® chart. With hierarchy, you can represent multiple levels of subcomponents in a system.

State Hierarchy Example

For example, this chart has three levels of hierarchy. Drawing one state within the boundaries of another state indicates that the inner state is a substate (or child) of the outer state (or superstate). The outer state is the parent of the inner state.

Chart the contains three levels of hierarchy.

In this example, the chart is the parent of the state Car_done. The state Car_done is the parent state of the Car_made and Car_shipped states. The state Car_made is also the parent of the Parts_assembled and Painted states. You can also say that the states Parts_assembled and Painted are children of the Car_made state.

To represent the Stateflow hierarchy textually, use a slash character (/) to represent the chart and use a period (.) to separate each level in the hierarchy of states. The following list is a textual representation of the hierarchy of objects in the preceding example:

  • /Car_done

  • /Car_done.Car_made

  • /Car_done.Car_shipped

  • /Car_done.Car_made.Parts_assembled

  • /Car_done.Car_made.Painted

Create Substates and Superstates

A substate is a state that can be active only when another state, called its parent, is active. States that have substates are known as superstates. To create a substate, click the State tool and drag a new state into the state you want to be the superstate. A Stateflow chart creates the substate in the specified parent state. You can nest states in this way to any depth. To change the parentage of a substate, drag it from its current parent in the chart and drop it in its new parent.


A parent state must be graphically large enough to accommodate all its substates. You might need to resize a parent state before dragging a new substate into it. You can bypass the need for a state of large graphical size by declaring a superstate to be a subchart. See Encapsulate Modal Logic by Using Subcharts for details.

Objects That a State Can Contain

States can contain all other Stateflow objects. Stateflow chart notation supports the representation of graphical object hierarchy in Stateflow charts with containment. A state is a superstate if it contains other states. A state is a substate if it is contained by another state. A state that is neither a superstate nor a substate of another state is a state whose parent is the Stateflow chart itself.

States can also contain nongraphical data, event, and message objects. The hierarchy of this containment appears in the Model Explorer. You define data, event, and message containment by specifying the parent object.

Related Topics