| Stateflow |
 |
Create a Stateflow Diagram
The following steps describe how to create a simple Stateflow diagram using the graphics editor:
- Double-click the Stateflow block in the Simulink model window to invoke the graphics editor window.
- Notice the tool icons the drawing toolbar that you will soon be using:

- Select the State tool button in the drawing toolbar.
- Move the cursor into the drawing area and left-click to place the state.
- Position the cursor over that state, click the right mouse button, and drag to another location in the drawing area to make a copy of the state. Release the right mouse button to drop the state at that location.
- Click the ? character within each state to enter each state label.
- Label the states with the titles
On and Off.
- Deselect the state to exit the edit.
- To deselect a state, click anywhere outside the state or press the Esc key. Your Stateflow diagram should look similar to the following:

- Draw a transition starting from the right side of state
On to the top of state Off as follows:
- Place the cursor at a straight portion of the right border of the
On state.
- When the cursor changes to crosshairs, click-drag the mouse to the top
border of the
Off state.
- When the transition snaps to the border of the
Off state, release the
mouse button.
- Your Stateflow diagram now an appearance similar to the following:

- Select the Junction button in the drawing toolbar.
- Move the cursor into the drawing area and click to place the junction as follows:

- Draw a transition segment from the state
Off to the junction as shown.

- Transitions exist only between one state and another. However, transitions can be made up of transition segments that define alternate flow paths with junctions.
- Draw a transition segment from the junction to the state
On as shown.

- Draw a transition segment from the junction to the state
Off as shown.

- Label the transition from the state
On to the state Off as follows:
- Click the transition to select it.
- Click the ? character that appears alongside the transition to obtain a
blinking cursor.
- Enter the label text
off_switch.
- Press the Escape key to deselect the transition label and exit edit mode
for this label.
- Label the transition segment from the state
Off to the junction with the text on_switch.
- Label the transition segment from the junction to the state
Off with the text [temp > 30].
- Your Stateflow diagram should now look similar to the following:

- Add a default transition to the state Off with the following steps:
- Select the Default Transition tool in the drawing toolbar.
- Move the mouse cursor to the top border of the
Off state.
- Click and release the mouse when the cursor's transition arrowhead
snaps straigh up and down to the border of the
Off state.
- Your finished Stateflow diagram should now look similar to the following:

| Note
For more information on creating Stateflow diagrams using the graphics editor, see Working with Charts.
|
| Create a Simulink Model | | Define Input Events |  |