Stateflow User's Guide Previous page   Next Page

Drawing Transitions in a Stateflow Diagram

States in a Stateflow diagram can be active or inactive. In Drawing States in Stateflow Diagrams, you draw an On state and an Off state for the SFcontrol1 model. An active Off state indicates the device you are controlling is off, and an active On state indicates that the device is on.

Because a device such as a motor or a fan cannot be on and off at the same time, only one state can be active at a time. The diagram needs to define a way to change the control state of the device from Off to On and from On to Off. Transitions in a Stateflow diagram define a path along which an active state can become inactive and another state can become active. In this topic, you draw transitions between the Off state and the On state with the following steps:

  1. Position the cursor at a straight portion of the left border of the Off state as shown.

  1. Notice that cross-hairs appear in place of the cursor. Cross-hairs do not appear if you place the cursor on the corner of a state. There, an angled double-arrow appears for resizing the state. Corners are used exclusively for resizing.

  1. When the cursor changes to cross-hairs, click-drag the mouse to the bottom border of the On state and release the mouse.
  1. The Stateflow diagram now has a transition similar to the following:

    Notice that a transition is directional. This transition proceeds from the Off state to the On state. This means that if the Off state is active, the On state can become active and the Off state inactive through this transition.

  1. Use the preceding steps to draw a transition from the right side of the state On to the top of the state Off as shown.

  1. This transition proceeds from the On state to the Off state. This means that if the On state is active, the Off state can become active and the On state inactive through this transition.

You need to add one last transition to tell the Stateflow diagram which of the two states, Off or On, is active when the Stateflow diagram starts operating. You use a default transition to specify the Off state as the first active state with the following steps:

  1. In the drawing toolbar, click the Default Transition tool .
  2. Move the cursor into the drawing area.
  1. Notice that the cursor is an arrow pointing down and to the right.

  1. Move the cursor to the right side of the top border of the Off state.
  1. When the cursor's arrowhead touches the top border of the Off state, it snaps straight up and down, as shown.

  1. Release the mouse and click an empty part of the diagram.
  1. You should now see a default transition pointing to the Off state, as shown.


Previous page  Drawing States in Stateflow Diagrams Adding a Trigger Event to the Stateflow Diagram Next page

© 1994-2005 The MathWorks, Inc.