Using Simulink Previous page   Next Page

Defining Inputs and Outputs

In the stats function header for the Embedded MATLAB Function block you define in Programming the Embedded MATLAB Function, the function argument vals is an input and mean and stdev are outputs. By default, function inputs and outputs inherit their data type and size from the Simulink signals attached to their ports. In this topic, you examine input and output data for the Embedded MATLAB Function block to verify that it inherits the correct type and size.

  1. If not already open, open the call_stats_block2 model that you save at the end of Programming the Embedded MATLAB Function, and double-click its Embedded MATLAB Function block stats to open it for editing.
  2. In the Embedded MATLAB Editor, click the Explorer tool to open the Model Explorer.
  1. The Model Explorer window appears, as shown.

    You use the Model Explorer to display and define arguments for Embedded MATLAB Function blocks. Notice that the Embedded MATLAB Function block Embedded MATLAB is highlighted in the left Model Hierarchy pane.

    The Contents pane displays the argument vals and the return values mean and stdev that you have already created for the Embedded MATLAB Function block. Notice that vals is assigned a Scope of Input, which is short for Input from Simulink. mean and stdev are assigned the Scope of Output, which is short for Output to Simulink.

  1. In the Contents pane of the Model Explorer window, click anywhere in the row for vals to highlight it, as shown.

  1. The right pane displays the Data properties dialog box for vals. By default, the type and size of input and output arguments are inherited from the Simulink signals attached to each input or output port. Inheritance of type is specified by setting Type to Inherited. Inheritance of size is specified by setting Size to -1.

    The actual inherited values for size and type are set during compilation of the model, and are reported in the CompiledType and CompiledSize columns of the Contents pane. You compile and build the model by clicking the Build tool , which you do in Checking the Function for Errors to check the Embedded MATLAB function for errors.

    If you want, you can specify the type of an input or output argument directly by selecting a type in the Type field of the Data properties dialog box, for example, double. You can also specify the size of an input or output argument directly by entering an expression in the Size field of the Data properties dialog box for the argument. For example, you can enter [2 3] in the Size field to size vals as a 2-by-3 matrix. See Typing Function Arguments and Sizing Function Arguments for more information on the expressions that you can enter for type and size.


Previous page  Checking the Function for Errors Debugging an Embedded MATLAB Function Next page

© 1994-2005 The MathWorks, Inc.