Stateflow User's Guide Previous page   Next Page

Drawing States in Stateflow Diagrams

You program the control behavior for a Stateflow block in its Stateflow diagram. In Opening the Diagram for a Stateflow Block, you open the empty Stateflow diagram for the Controller Stateflow block. Now you need to graphically program it with its control behavior.

States are objects in a Stateflow diagram that represent modes of operation for a control device. In this example, a control device has two states of operation: on and off. Start programming the Stateflow diagram for the Controller block by drawing the states On and Off in the following steps:

  1. In the drawing toolbar on the left, click the State tool .
  2. Move the cursor into the drawing area and notice that the cursor takes the shape of a box with rounded corners.
  3. In the upper-left corner of the drawing area, click to place a new state, as shown.
  1. A highlighted state appears with a blinking text cursor in the upper-left corner of the state, as shown.

  1. Enter the text On and click outside of the state.
  1. This gives the new state the name On. You enter the name for a state at the beginning of its label.

    The Stateflow diagram editor should now have the following appearance:

  1. Use the preceding steps to draw and label a new state in the lower-right corner of the Stateflow diagram editor with the name Off, as shown.

Stateflow diagrams are a form of a finite state machine. Finite state machines use states to represent the possible control modes of an object. You have just created two states named On and Off. These two states represent the two control modes for a single-speed fan: on and off. But they can also represent the control modes of a host of other devices that can be on or off, such as a light switch, a heater, and so on.


Previous page  Opening the Diagram for a Stateflow Block Drawing Transitions in a Stateflow Diagram Next page

© 1994-2005 The MathWorks, Inc.