Stateflow User's Guide Previous page   Next Page

Adding a Graphical Function

You can shorten conditions on transitions with a graphical function. Add a graphical function to the Stateflow diagram of sf_control4.mdl with the following steps:

  1. If not already loaded, load the Simulink model SFcontrol4 you save in Adding a Junction for Flow Control and double-click the Stateflow block Controller to open it.

  2. Resize the window by click-dragging the right border of the Stateflow diagram to the right by about 3 inches.
  3. In the Stateflow diagram editor, click the Graphical Function tool .
  4. Place the cursor, now in the shape of the box, on the right side of the diagram.
  1. A highlighted function box appears with a blinking cursor in its upper-right corner as shown.

  1. Enter the text
  1. and click outside the function box.

  1. Place the mouse cursor over the lower-right corner of the function box.
  1. The mouse cursor now appears as a double arrow.

  1. Click-drag the function box corner to the right about three inches to resize the function box as shown.

  2. Select the Default Transition tool

    and place the mouse cursor inside the function box in the lower-right corner and click.
  1. This places a junction with an incoming default transition in the lower-right corner of the function box as shown.

  1. Click-drag the source of the default transition to the left side of the function box as shown.

  2. Click the question mark (?) on the default transition and label it as follows:
  1. The statement {r = temp >= 120;} is an example of a transition condition action. A condition action is executed when the condition for its transition is true. Because the default transition has no condition, its condition action is executed automatically and the default transition is taken into the junction. In this case, when the function hot is called, the logical result of the comparison of the temperature with 120 is stored in the return data r.

    A default transition into a junction is a type of flow diagram. Flow diagrams use transitions and junctions. You can use more complicated flow diagrams to represent common code structures like for loops and if-then-else constructs without the use of states. Flow diagrams are discussed in more detail later on in Using Junctions in Flow Diagrams.

  1. Double-click the function box to group it.
  1. This joins the function and the objects it contains into a group of objects that you can move as a unit. The finished diagram should now appear similar to the following:


Previous page  Adding a Graphical Function for Convenience Calling a Graphical Function Next page

© 1994-2005 The MathWorks, Inc.