Group Chart Objects by Using Boxes - MATLAB & Simulink (original) (raw)

A box is a graphical object that defines a namespace that you can use to organize objects in your chart, such as states, functions, and data. Boxes allow you to quickly glance at your chart and recognize which states or functions work together to perform certain tasks.

Boxes have square corners to distinguish them from states, which have rounded corners. Boxes are not supported in standalone Stateflow® charts in MATLAB®.

In this chart, the box Heater groups together the related statesOff and On.

Chart modeling a bang-bang controller.

For more information about this example, see Model Bang-Bang Temperature Control System.

Semantics of Stateflow Boxes

Hierarchy of Graphical Objects in Boxes

Boxes add a level of hierarchy to Stateflow charts. If you refer to a box-parented function or state from outside of the box, you must include the box name in the path. See Group Functions Using a Box.

Guidelines for Using Boxes

When you use a box:

Draw and Edit a Box

Create a Box

You create boxes in your chart by using the Box icon in the object palette.

  1. In the object palette, click the Box tool.
  2. On the chart canvas, click the location for the new box. The new box appears with the cursor in place to add a name.
  3. Enter a name for the box and then click outside of the box.

Delete a Box

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

Examples of Using Boxes

Group Functions Using a Box

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

Chart that uses a box to group two MATLAB functions.

The chart executes in this order:

  1. The state Cold activates first.
  2. Upon entry, the state Cold invokes the functionStatus.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 functionStatus.msgWarm.
    This function displays a status message that the temperature is warm.
  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.

Group States Using a Box

This chart shows a box named Status that groups related states.

Chart that uses a box to group two parallel substates.

In this chart:

See Also

Stateflow.Annotation

Topics