Products & Services Solutions Academia Support User Community Company

Learn more about Stateflow   

Using Boxes to Extend Charts

When to Use Boxes

Use boxes to organize graphical objects in your chart.

Semantics of 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 by drawing them in the Stateflow Editor with the box tool shown below.

  1. Select the Box tool.

  2. Move your pointer into the drawing area.

    In the drawing area, your pointer becomes box-shaped.

  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.

    A text cursor appears in place of the question mark.

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

Deleting a Box

To delete a box, click it to select it and choose Edit > Cut from the context menu or press the Delete key.

Changing a State to a Box

You can change an existing state to a box and back to a state with this procedure:

  1. Right-click the state.

  2. From the context menu, select Type.

    A submenu appears adjacent to the context menu.

  3. From the submenu, select Box.

    This action converts the state to a box, redrawing its border with sharp corners to indicate its changed status.

  4. Repeat the preceding steps on the box and select State from the submenu instead of Box to change the box to a state.

Examples of Using Boxes

Using a Box to Group Functions

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

Chart execution takes place as follows:

  1. The state Cold activates first.

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

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

      Note   Because the Embedded 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 Embedded MATLAB function Status.msgWarm.

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

      Note   Because the Embedded 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:

  


Related Products & Applications

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