Stateflow User's Guide Previous page   Next Page

Sharing Input and Output Data with Simulink

In Setting Data Properties in the Data Dialog, you define data in its properties dialog. In this topic, you continue to use the properties dialog to define Stateflow data that is input from or output to the Simulink model.

Input data is data that a Simulink model supplies to a chart with input ports on the chart block. Output data is data that a chart supplies to other blocks via its output ports. The following example shows a Stateflow chart block with input and output data ports connected to the Simulink model.

To define data as input from or output to Simulink, do the following:

  1. Add a data object to the chart using the Stateflow diagram editor or Stateflow Explorer (see Adding Data to the Data Dictionary).
  1. You must add the data to the chart and not to any other object in the chart. Adding a data object with the Stateflow diagram editor adds it only to the chart that is visible in the diagram editor. If you add the data in the Model Explorer, you must select (highlight) the chart object in the Model Hierarchy pane of the Model Explorer before adding the event.

  1. In the Model Explorer, set the property Scope to one of the following:
  1. When you define data to be Input to Simulink, a Simulink input port is added to the Stateflow block. When you define a data object to be Output to Simulink, a Simulink output port is added to the Stateflow block.

    By default, Stateflow associates the first input port with the first input item you define, the second input port with the second input item, and so on. The same applies to output ports. Both the Model Explorer and the Data dialog show the current port assignment in the Port field. You can alter this assignment by editing the value displayed in the Port field.

  1. Set the type of the input or output data.
  1. You use the Type property for input or output data, to size it directly by an expression or specify that Stateflow inherit the type from Simulink. For more information on defining data types in Stateflow, see Typing Stateflow Data.

    If the Use Strong Data Typing with Simulink I/O option for the chart is selected (see Specifying Chart Properties), the following apply:

    If the Use Strong Data Typing with Simulink I/O option is not selected for the chart, the following apply:

  1. Set the size of the input or output data.
  1. You use the Size property for input or output data to size it directly by a mathematical expression or specify that Stateflow inherit the size from Simulink. For more information on defining data sizes in Stateflow, see Sizing Stateflow Data.

    If you specify the size of input or output data directly by a mathematical expression, you can set it to be a scalar or a matrix (two-dimensional, row-by-column array). The size of the Simulink signal connected to a Stateflow input port must match the size of the Stateflow data associated with the port. The size of Stateflow data associated with an output port must match the size expected by the destination block in Simulink it is connected to.

    Data arrays you specify with only one dimension are compatible with Simulink row or column vectors of the same size. For example, if Stateflow defines input or output data of size 3, it is compatible with a Simulink row vector of size [1,3], or column vector of size [3,1].


Previous page  Sharing Stateflow Data with Simulink and MATLAB Resolving Signal Objects for Output Data Next page

© 1994-2005 The MathWorks, Inc.