| 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… |
|---|
Use boxes to organize graphical objects in your chart.
Boxes add a level of hierarchy to Stateflow charts. This property affects visibility of functions and states inside a box to objects that reside outside of the box. If you refer to a box-parented function or state from a location outside of the box, you must include the box name in the path. See Using a Box to Group Functions.
Boxes affect the implicit activation order of parallel states in a chart. If your chart uses implicit ordering, parallel states within a box wake up before other parallel states that are lower or to the right in that chart. Within a box, parallel states wake up in top-down, left-right order. See Using a Box to Group States.
Note To specify activation order explicitly on a state-by-state basis, you must select User specified state/transition execution order in the Chart properties dialog box. This option is selected by default when you create a new Stateflow chart. For details, see Explicit Ordering of Parallel States. |
When you use a box, these rules apply:
You must include the box name in the path when you refer to a box-parented function or state from a location outside of the box.
You can move or draw graphical objects inside a box, such as functions and states.
You can draw a state around the objects you want inside it and then convert that state to a box. See Changing a State to a Box.
You can add data to a box so that all the elements in the box can share the same data.
You can group a box and its contents into a single graphical element. See Grouping States.
You can subchart a box to hide its elements. See Using Subcharts to Extend Charts.
You cannot define action statements for a box, such as entry, during, and exit actions.
You cannot define a transition to or from a box. However, you can define a transition to or from a state within a box.
You create boxes by drawing them in the Stateflow Editor with the box tool shown below.

Move your pointer into the drawing area.
In the drawing area, your pointer becomes box-shaped.
Click in any location to create a box.
The new box appears with a question mark (?) name in its upper left corner.
Click the question mark label.
A text cursor appears in place of the question mark.
To delete a box, click it to select it and choose Edit > Cut from the context menu or press the Delete key.
You can change an existing state to a box and back to a state with this procedure:
From the context menu, select Type.
A submenu appears adjacent to the context menu.
This action converts the state to a box, redrawing its border with sharp corners to indicate its changed status.
Repeat the preceding steps on the box and select State from the submenu instead of Box to change the box to a state.
This chart shows a box named Status that groups together Embedded MATLAB functions.

Chart execution takes place as follows:
The state Cold activates first.
Upon entry, the state Cold invokes the Embedded MATLAB function Status.msgCold.
This function displays a status message that the temperature is cold.
If the value of the input data temp exceeds 80, a transition to the state Warm occurs.
Upon entry, the state Warm invokes the Embedded MATLAB function Status.msgWarm.
This function displays a status message that the temperature is warm.
If the value of the input data temp drops below 60, a transition to the state Cold occurs.
Steps 2 through 5 repeat until the simulation ends.
This chart shows a box named Status that groups together related states. The chart uses implicit ordering for parallel states, instead of the default explicit mode. (For details, see Implicit Ordering of Parallel States.)

The main ideas of this chart are:
The state Temp wakes up first, followed by the state Wind_Chill. Then, the state Monitor wakes up.
Based on the input data temp, transitions between substates occur in the parallel states Status.Temp and Status.Wind_Chill.
When the transition from Status.Temp.Cold to Status.Temp.Warm occurs, the transition condition in(Status.Temp.Warm) becomes true.
When the transition from Status.Temp.Warm to Status.Temp.Cold occurs, the transition condition in(Status.Temp.Cold) becomes true.
Note Because the substates Status.Temp.Cold and Status.Temp.Warm reside inside a box, the argument of the in operator must include the box name Status. If you omit this prefix, an error message appears. For information about the in operator, see Checking State Activity. |
![]() | Using Graphical Functions to Extend Actions | Using Notes to Extend Charts | ![]() |

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