Stateflow Previous page   Next Page

Create a Stateflow Diagram

The following steps describe how to create a simple Stateflow diagram using the graphics editor:

  1. Double-click the Stateflow block in the Simulink model window to invoke the graphics editor window.

  1. Notice the tool icons the drawing toolbar that you will soon be using:

  1. Select the State tool button in the drawing toolbar.
  2. Move the cursor into the drawing area and left-click to place the state.
  3. 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.
  4. Click the ? character within each state to enter each state label.

  1. Label the states with the titles On and Off.

  1. Deselect the state to exit the edit.

  1. To deselect a state, click anywhere outside the state or press the Esc key. Your Stateflow diagram should look similar to the following:

  1. Draw a transition starting from the right side of state On to the top of state Off as follows:
    1. Place the cursor at a straight portion of the right border of the On state.

    1. When the cursor changes to crosshairs, click-drag the mouse to the top border of the Off state.
    2. When the transition snaps to the border of the Off state, release the mouse button.

  1. Your Stateflow diagram now an appearance similar to the following:

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

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

  1. Transitions exist only between one state and another. However, transitions can be made up of transition segments that define alternate flow paths with junctions.

  1. Draw a transition segment from the junction to the state On as shown.

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

  3. Label the transition from the state On to the state Off as follows:
    1. Click the transition to select it.
    2. Click the ? character that appears alongside the transition to obtain a blinking cursor.
    3. Enter the label text off_switch.
    4. Press the Escape key to deselect the transition label and exit edit mode for this label.

  4. Label the transition segment from the state Off to the junction with the text on_switch.
  5. Label the transition segment from the junction to the state Off with the text [temp > 30].

  1. Your Stateflow diagram should now look similar to the following:

  1. Add a default transition to the state Off with the following steps:
    1. Select the Default Transition tool in the drawing toolbar.
    2. Move the mouse cursor to the top border of the Off state.
    3. Click and release the mouse when the cursor's transition arrowhead snaps straigh up and down to the border of the Off state.

  1. Your finished Stateflow diagram should now look similar to the following:


Previous page  Create a Simulink Model Define Input Events Next page

 © 1994-2009 The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS