When a Simulink Function block is within the scope of a Function Caller block, you do not have to specify the parameters. In such a case, the Function Caller block can determine the input and output argument specifications.
You specify arguments when a Simulink Function block is outside the scope of a Function Caller block. A Simulink Function block is considered to be out of scope of a Function Caller block when the two blocks are in separate models referenced by a common parent model.
This table lists possible input and output argument specifications.
Simulink Function Block Data Type | Function Caller Block Expression | Description |
---|---|---|
double | double(1.0) | Double-precision scalar. |
double | double(ones(12,1)) | Double-precision column vector of length 12. |
single | single(1.0) | Single-precision scalar. |
int8 , int16 ,
int32 | int8(1) , int16(1) ,
int32(1) | Integer scalars. |
int32([1 1 1]) | Integer row vector of length 3. | |
int32(1+1i) | Complex scalar whose real and imaginary parts are 32-bit integers. | |
uint8 , int16 ,
int32 | uint8(1) , uint16(1) ,
uint32(1) | Unsigned integer scalars. |
boolean | boolean(true) ,boolean(false) | Boolean, initialized to true (1) or false (0). |
|
| 16-bit fixed-point signed scalar with binary point set to zero. Fixed-point numbers can have a word size up to 128 bits. |
fixdt(1,16,4) | fi(0,1,16,4) | 16-bit fixed-point signed scalar with binary point set to 4. |
fixdt(1,16,2^0,0) | fi(0,1,16,2^0,0) | 16-bit fixed-point signed scalar with slope set to 2^0 and
bias set to 0. |
Bus: <object name> | parameter object name | Simulink.Parameter object with the
Value parameter set to a MATLAB® structure for the bus. |
Enum: <class name> | parameter object name | Simulink.Parameter object with the
Value parameter set to an enumerated value. |
<alias name> | parameter object name | Simulink.Parameter object with the
DataType parameter set to a Simulink.AliasType object and the
Value parameter set to a value. |
Create a bus with two signals, and then specify the Input argument specification parameter for a Function Caller block. The Function Caller block calls a Simulink Function block that accepts the bus as input.
A bus input to a Function Caller block must be a non-virtual bus using a bus object.
Create a Simulink® bus object myBus
.
myBus = Simulink.Bus;
Add elements A
and B
.
myBus.Elements(1).Name = 'A'; myBus.Elements(2).Name = 'B';
Create a MATLAB structure myBus_MATLABstruct
with fields
A
and B
.
myBus_MATLABStruct.A = 0; myBus_MATLABStruct.B = 0;
Create a Simulink parameter object myBus_parameter
and assign the
MATLAB structure to the Value
parameter.
myBus_parameter = Simulink.Parameter; myBus_parameter.DataType = 'Bus: myBus'; myBus_parameter.Value = myBus_MATLABStruct;
For the Function Caller block dialog box, set the Input argument
specification parameter to myBus_parameter
.
For the Argument In block dialog box of the Simulink Function block,
set the Data type parameter to Bus:
myBus
.
Create an enumerated data type for the three primary colors, and then specify the Input argument specification parameter for a Function Caller block. The Function Caller block calls a Simulink Function block that accepts a signal with the enumerated type as input.
Create a MATLAB file for saving the data type definition. On the MATLAB toolstrip, select New > Class.
In the MATLAB editor, define the elements of an enumerated data type. The class
BasicColors
is a subclass of the class
Simulink.IntEnumType
.
classdef BasicColors < Simulink.IntEnumType enumeration Red(0) Yellow(1) Blue(2) end end
Save the class definition in a file named BasicColors.m
.
Create a Simulink parameter object myEnum_parameter
and assign one of the
enumerated values to the Value
parameter.
myEnum_parameter = Simulink.Parameter; myEnum_parameter.Value = BasicColors.Red;
For the Function Caller block dialog box, set the Input
argument specification. to myEnum_parameter
.
For the Argument In block dialog box within a Simulink Function
block, set the Data type parameter to Enum:
BasicColors
.
Create an alias name for the data type single, and then specify the Input argument specification parameter for a Function Caller block. The Simulink Function block called by the Function Caller block also uses the alias name to define the input data type.
Create a Simulink alias data type object myAlias
.
myAlias = Simulink.AliasType;
Assign a data type.
myAlias.BaseType = 'single';
Create a Simulink parameter object myAlias_parameter
and assign the alias
name to the DataType
parameter.
myAlias_parameter = Simulink.Parameter; myAlias_parameter.DataType = 'myAlias'; myAlias_parameter.Value = 1;
For the Function Caller block dialog box, set the Input
argument specification parameter to myAlias_parameter
.
For the Argument In block dialog box within a Simulink Function
block, set the Data type parameter to
myAlias
.