Create Model That Uses MATLAB Function Block
Create Model That Uses MATLAB Function Block
From the Sources library, add a Constant block to the left of the MATLAB
Function block and set its value to the vector [2 3 4 5].
From the Sinks library, add two Display blocks to the right of the MATLAB
Function block.
3. In the Simulink Editor, select File > Save As and save the model as call_stats_block1.
The function stats calculates a statistical mean and standard deviation for the values in
the vector vals. The function header declares vals as an argument to the stats function,
with mean and stdev as return values.
4. Save the model as call_stats_block2.
5. Complete the connections to the MATLAB Function block as shown.
6. In the MATLAB Function Block Editor, enter a line space after the function header and
add the following code:
7. %
8. %
9.
10.
11.
12.
13.
14.
15.
16.
The left pane displays the argument vals and the return values mean and stdev that you
have already created for the 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.
3. In the left pane of the Ports and Data Manager, click anywhere in the row for vals to
highlight it.
The right pane displays the Data properties dialog box for vals. By default, the class,
size, and complexity of input and output arguments are inherited from the signals
attached to each input or output port. Inheritance is specified by setting Size to -1,
Complexity to Inherited, and Type to Inherit: Same as Simulink.
The actual inherited values for size and type are set during compilation of the model, and
are reported in the Compiled Type and Compiled Size columns of the left pane.
You can specify the type of an input or output argument 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 by entering an expression in the Size field. For
example, you can enter [2 3] in the Size field to specify vals as a 2-by-3 matrix. See
Type Function Arguments and Size Function Arguments for more information on the
expressions that you can enter for type and size.