| Stateflow® | ![]() |
| On this page… |
|---|
You can create charts within charts. A chart that is embedded in another chart is called a subchart. The subchart can contain anything a top-level chart can, including other subcharts. In fact, you can nest subcharts to any level.
A subcharted state is a superstate of the states and charts that it contains. It appears as a block with its name in the block center. However, you can define actions and default transitions for subcharts just as you can for superstates. You can also create transitions to and from subcharts just as you can create transitions to and from superstates. Further, you can create transitions between states residing outside a subchart and any state within a subchart. The term supertransition refers to a transition that crosses subchart boundaries in this way. See Using Supertransitions to Extend Transitions for more information.
Subcharts enable you to reduce a complex chart to a set of simpler, hierarchically organized charts. This makes the chart easier to understand and maintain. Nor do you have to worry about changing the semantics of the chart in any way. Subchart boundaries are ignored during simulation and code generation.
Subcharts define a containment hierarchy within a top-level chart. A subchart or top-level chart is the parent of the charts it contains at the first level and an ancestor of all the subcharts contained by its children and their descendants at lower levels.
You create a subchart by converting an existing state, box, or graphical function into the subchart. The object to be converted can be one that you have created expressly for the purpose of making a subchart or it can be an existing object whose contents you want to turn into a subchart.
To convert a new or existing state, box, or graphical function to a subchart:
Select the object and right-click a state to display the shortcut menu for that state.

Select Subcharted from the resulting submenu.
This action converts the state (or a graphical function or box) to a subchart.

Note When you convert a box to a subchart, the subchart retains the attributes of a box. In particular, the resulting subchart's position in the chart determines its activation order (see Using Boxes to Extend Charts for more information). |
To convert the subchart back to its original form, right-click the subchart. In the pop-up menu that results, select Make Contents. In the resulting submenu, select Subcharted.
Caution You cannot undo the operation of converting a subchart back to its original form. When you perform this operation, the undo and redo buttons are disabled from undoing and redoing any prior operations. |
Subcharts also act as individual objects. You can move, copy, cut, paste, relabel, and resize subcharts as you would states and boxes. You can also draw transitions to and from a subchart and any other state or subchart at the same or different levels in the chart hierarchy (see Using Supertransitions to Extend Transitions).
Opening a subchart allows you to view and change its contents. To open a subchart, do one of the following:
Double-click anywhere in the box that represents the subchart.
Select the box representing the subchart and press the Enter key.
The contents of the subchart appear, as shown.

A shaded border surrounds the contents of the subchart. The border displays supertransitions.
To return to the previous view, select Back from the shortcut menu, press the Esc key on your keyboard, or select the up or back arrow on the toolbar.
After you open a subchart (see Opening a Subchart), you can perform any editing operation on its contents that you can perform on a top-level chart. This means that you can create, copy, paste, cut, relabel, and resize the states, transitions, and subcharts in a subchart. You can also group states, boxes, and graphical functions inside subcharts.
You can also cut and paste objects between different levels in your chart. For example, to copy objects from a top-level chart to one of its subcharts, first open the top-level chart and copy the objects. Then open the subchart and paste the objects into the subchart.
Transitions from outside subcharts to states or junctions inside subcharts are called supertransitions. You create supertransitions differently than you do ordinary transitions. See Using Supertransitions to Extend Transitions for information on creating supertransitions.
The Stateflow® Editor toolbar contains a set of buttons for navigating a chart's subchart hierarchy.
Note You can also use the key sequence .. (that is, press the period key twice) to navigate up to the parent object for a subcharted state, box, or function. |
![]() | Using History Junctions to Extend Charts and States | Using Supertransitions to Extend Transitions | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |