Skip to Main Content Skip to Search
Product Documentation

Grouping Chart Objects with Boxes

When to Use Boxes

Use a Stateflow box to organize graphical objects in your chart.

Semantics of Stateflow Boxes

Visibility of Graphical Objects in Boxes

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.

Activation Order of Parallel States

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.

Rules for Using Boxes

When you use a box, these rules apply:

Drawing and Editing a Box

Creating a Box

You create boxes in your chart by using the box tool shown below.

  1. Click the Box tool.

  2. Move your pointer into the drawing area.

  3. Click in any location to create a box.

    The new box appears with a question mark (?) name in its upper left corner.

  4. Click the question mark label.

  5. Enter a name for the box and then click outside of the box.

Deleting a Box

To delete a box, click to select it and press the Delete key.

Examples of Using Boxes

Using a Box to Group Functions

This chart shows a box named Status that groups together MATLAB functions.

Chart execution takes place as follows:

  1. The state Cold activates first.

  2. Upon entry, the state Cold invokes the function Status.msgCold.

    This function displays a status message that the temperature is cold.

      Note   Because the MATLAB function resides inside a box, the path of the function call must include the box name Status. If you omit this prefix, an error message appears.

  3. If the value of the input data temp exceeds 80, a transition to the state Warm occurs.

  4. Upon entry, the state Warm invokes the function Status.msgWarm.

    This function displays a status message that the temperature is warm.

      Note   Because the MATLAB function resides inside a box, the path of the function call must include the box name Status. If you omit this prefix, an error message appears.

  5. If the value of the input data temp drops below 60, a transition to the state Cold occurs.

  6. Steps 2 through 5 repeat until the simulation ends.

Using a Box to Group States

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:

  


Free Stateflow Interactive Kit

Learn how engineers use Stateflow to model state machines in their Simulink models.


Get free kit

Trials Available

Try the latest version of Stateflow.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS