|On this page…|
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 Group Functions Using a Box.
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 Group States Using a Box.
Note: To specify activation order explicitly on a state-by-state basis, select User specified state/transition execution order in the Chart properties dialog box. This option is selected by default when you create a new chart. For details, see Explicit Ordering of Parallel States.
When you use a box, these rules apply:
Include the box name in the path when you use dot notation to 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 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 Group States.
You can subchart a box to hide its elements. See Encapsulate Modal Logic Using Subcharts.
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 in your chart by using the box tool shown below.
The new box appears with a question mark (?) name in its upper left corner.
To delete a box, click to select it and press the Delete key.
This chart shows a box named Status that groups together MATLAB® functions.
Chart execution takes place as follows:
The state Cold activates first.
Upon entry, the state Cold invokes the 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 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 Check State Activity.