Stateflow    

Creating a Graphical Function

To create a graphical function, do the following:

  1. Create a state in your model where you want the function to appear.
  1. Select Function from the Type submenu of the newly created state's shortcut menu.
  1. Stateflow converts the state to a graphical function.

    The new function appears as an unnamed object in the Stateflow Explorer.

  1. Enter a function prototype in the function label.
  1. The return values and arguments that you declare in the prototype appear in the Explorer as data items parented by the function object.

    The Scope field in the Explorer indicates the role of the corresponding argument or return value. Arguments have scope Input. Return values have scope Output. The number that appears in parentheses for the scope of each argument is the order in which the argument appears in the function's prototype. When a Stateflow action invokes a function, it passes arguments to the function in the same order.

  1. Specify the data properties (data type, initial value, and so on) of the function's arguments and return values (if it has any).
  1. See Setting Data Properties for information on setting data properties. The following restrictions apply to argument and return value properties.

  1. Create any additional data items that the function might need to process when it is invoked.
  1. See Adding Data to the Data Dictionary for information on how to create data items. A function can access only items that it owns. Thus, any items that you create for use by the function must be created as children of the function. The items that you create can have any of the following scopes:

  1. Create a flow diagram within the function that performs the action to be performed when the function is invoked.
  1. At a minimum, the flow diagram must include a default transition terminated by a junction. The following example shows a minimal flow diagram for a graphical function that computes the product of its arguments.

  1. If you prefer, hide the function's contents by selecting Subcharted from the Make Contents menu of the function's shortcut menu.


  Using Graphical Functions in Stateflow Charts Calling Graphical Functions