| Stateflow User's Guide | ![]() |
Creating a Function
You create a Stateflow graphical, truth table, or embedded MATLAB function in Stateflow diagrams with the following steps:
| Tool |
Function |
| Graphical |
|
| Truth Table |
|
| Embedded MATLAB |
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.
A function can reside anywhere in a chart, state, or subchart. The location of a function determines its scope, that is, the set of states and transitions that can call the function. In particular, functions are visible to the chart, to the parent state and its parents, and to sibling transitions and states with the following exceptions.
where func is the function's name, a1, a2, an are formal names for its arguments, and r is the formal name for its return value (only one return is allowed). Arguments and return values can be scalars, vectors, or 2-dimensional matrices of any type. Matrices with a row or column dimension of 1 are treated as row or column vectors, respectively.
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.
| Using Functions to Extend Actions | Programming Functions | ![]() |
© 1994-2005 The MathWorks, Inc.