| Stateflow User's Guide |
 |
Converting a State to a Subchart
Let's suppose that you want to add more substates to the superstate On that you create in Adding a Superstate. You can always click-drag the edges of the Stateflow diagram editor window to make it as big as possible. However, if you add enough substates, you could easily run out of room and start to impinge on other elements of the diagram. Instead, you can turn the On state into its own chart, a subchart, with the following steps:
- If not already loaded, load the Simulink model
SFcontrol6 you save in Adding Superstates to Simplify Control and save it as SFcontrol7.
- Double-click on the Stateflow block Controller to open it.

- Right-click on the state On.
- In the resulting pop-up menu, select Make Contents followed by Subcharted in the submenu that results.
- The state On now becomes opaque as shown.

- Double-click the On state.
- The On state and its contents now appear in a chart of their own, a subchart.

- Vertically enlarge the subchart window and the state On to have the following appearance:

- As a subchart, the state On can be any size.
- At the bottom of state On, add a new state named No with the entry action
speed = 0;.
- Delete the default transition to the state Lo and add a new default transition to the state No.
- Only one substate can be the default state for a superstate.
- Draw a transition from No to Lo and label it
[!cool()].
- Draw a transition from Lo to No and label it
[cool()].
- This is what you should now see:

- In the Stateflow diagram editor, click the Up to Controller tool
.
- Focus returns to the original Stateflow diagram.
- Add the function
cool() and group it, as shown.

- You can now resize the state On and move other diagram objects to make the diagram appear a little neater, as shown.

- Save the model (
SFcontrol7).
| Creating Subcharts to Add More Substates | | Simulating a Subchart |  |
© 1994-2005 The MathWorks, Inc.