Stateflow User's Guide Previous page   Next Page

Creating a Function

You create a Stateflow graphical, truth table, or embedded MATLAB function in Stateflow diagrams with the following steps:

  1. Select a drawing tool for the function from the Stateflow drawing toolbar as follows:

    Tool
    Function

    Graphical


    Truth Table


    Embedded MATLAB

  2. Move the cursor to the location for the new function and click to place it.
  1. The new function appears as an unnamed object in the Stateflow diagram editor with a flashing text cursor as seen in the following graphical function example.

    The new function also appears in the Model Explorer as a child of the chart or state in which it is drawn. In the following example, a graphical function is added to its parent Stateflow chart, myChart.

  1. Enter the function signature and click outside of the function box.
  1. The function signature specifies a name for the function and formal names for its arguments and return value. A signature has the following syntax:

  1. The following example shows a signature for a graphical function named f1 that takes two arguments, a and b, and returns a value y.

    Notice that the function box in the preceding example has been enlarged to accomodate the width of its label signature. You enlarge function boxes in their corners, just as for state and box objects.

    The signature for a function appears as a property of its owning object in the Model Explorer.

    If you expand the parent object in the Model Explorer, you can see the return values and arguments that you declare in the signature for a function as data items parented by the function.

    The Scope field in the Explorer indicates the role of each argument or return value. Arguments have the scope Function input, and return values have scope Function output.


Previous page  Using Functions to Extend Actions Programming Functions Next page

© 1994-2005 The MathWorks, Inc.