Stateflow User's Guide Previous page   Next Page

Creating Truth Table Data in Stateflow and Simulink

When you create a truth table with its own signature, you specify data for it in the form of a return value (t) and argument values (x, y, z). When you specify a call to a truth table, as you did in Calling a Truth Table in a Stateflow Action, you specify data that you pass to the return and argument values of the truth table (d, a, b, and c). Now you need to define this data for the Stateflow diagram in the following steps:

  1. In the Truth Table editor, select the Goto Explorer tool .
  1. The Model Explorer window appears as shown.

    The Goto Explorer button is a convenience for accessing the Model Explorer from the truth table editor. Notice in the Model Hierarchy pane (left pane) that the node for the function ttable is highlighted and that the Contents pane (right pane) displays the inputs (x, y, z) and outputs (t) for ttable. By default, these data are defined as scalars of type double. If you want to redefine these data with a different array size and type, you do it in the Model Explorer. However, no changes are necessary for this example.

    Notice also in the Model Hierarchy pane that the node above the function ttable is a node for the Stateflow block Chart. This is the name of the Stateflow diagram that contains the truth table ttable.

  1. In the Model Hierarchy pane, select Chart as shown.

  1. Notice that Chart contains no data in the Contents pane. You need to add the return and argument data used in calling ttable.

  1. From the Add menu, select Data.
  1. A scalar data of type double is added to the chart in the Contents pane of Explorer with the default name data.

    This data matches argument x in type and size, but still needs a change in name and scope.

  1. In the Contents pane, double-click the entry data in the Name column.
  1. A small text field opens with the name data highlighted.

  1. In the text field, change the name to a and press Enter.
  2. Click the entry Local under the Scope column.
  1. A menu of selectable scopes appears with Local selected.

  1. Select Input and press Enter.
  1. The scope Input (short for Input from Simulink) means that Simulink provides the value for this data, which it passes to the Stateflow diagram through an input port on the Stateflow block.

    You should now see the new data a in the Contents pane as shown.

  1. Use steps 3 through 7 to add the data b and c with the scope Input, and data d with a scope of Output (short for Output to Simulink).
  1. The scope Output to Simulink means that the Stateflow chart provides this data and passes it to Simulink through an output port on the Stateflow block.

    You should now see the following data in Stateflow Explorer:

    The data a, b, c, and d match their counterparts x, y, z, and t in the truth table signature in size (scalar) and type (double), but have a source outside the Stateflow block. Notice that input ports for a, b, and c, and an output port for d appear for the Stateflow block in the Simulink model.

  1. Complete connections to the Simulink diagram as shown.

  2. From the File menu, select Save to save the model.

Previous page  Calling a Truth Table in a Stateflow Action Programming a Truth Table Next page

© 1994-2005 The MathWorks, Inc.