Create Input and Output Ports
Creating Input Ports for Level-2 MATLAB S-Functions
To create and configure input ports, the
setup method should
first specify the number of S-function input ports, using the run-time object
NumInputPorts property. Next, if all input ports inherit
their functional properties (data type, dimensions, complexity, and sampling mode)
from their input signals, include the following line in the
Then, for each input port, the
setup method can specify
The dimensions of the input port, using
To individually specify that an input port's dimensions are dynamically sized, assign a value of
-1to the dimensions. In this case, you can implement the
SetInputPortDimensionsmethod to set the dimensions during signal propagation.
Whether the input port has direct feedthrough, using
A port has direct feedthrough if the input is used in the
Outputsfunctions to calculate either the outputs or the next sample time hit. The direct feedthrough flag for each input port can be set to either
0=no. Setting the direct feedthrough flag to
0tells the Simulink® engine that
uis not used to calculate the outputs or next sample time hit. Violating this leads to unpredictable results.
The data type of the input port, using
block.InputPort(. See the explanation for the DatatypeID property in the
Simulink.BlockDatadata object reference page for a list of valid data type IDs.
If you want the data type of the port to depend on the data type of the port to which it is connected, specify the data type as
-1. In this case, you can implement the
SetInputPortDataTypemethod to set the data type during signal propagation.
The numeric type of the input port, if the port accepts complex-valued signals, using
If you want the numeric type of the port to depend on the numeric type of the port to which it is connected, specify the numeric type as
'Inherited'. In this case, you can implement the
SetInputPortComplexSignalmethod to set the numeric type during signal propagation.
For an example that configures a Level-2 MATLAB® S-function with multiple input and output ports, open the model
sldemo_msfcn_lms and inspect the S-function
Creating Output Ports for Level-2 MATLAB S-Functions
To create output ports for Level-2 MATLAB S-functions the
setup method should first specify
the number of S-function output ports, using the run-time object
NumOutputPorts property. Next, if all output ports inherit
their functional properties (data type, dimensions, complexity, and sampling mode),
include the following line in the
Configure the output ports exactly as you configure input ports. See Creating Input Ports for Level-2 MATLAB S-Functions for a list of
properties you can specify for each output port, substituting
InputPort in each call to
the run-time object.
Scalar Expansion of Inputs
Scalar expansion of inputs refers conceptually to the process of expanding scalar input signals to the same dimensions as wide input signals connected to other S-function input ports. This is done by setting each element of the expanded signal to the value of the scalar input.
A C MEX S-function's
mdlInitializeSizes method enables scalar
expansion of inputs by setting the
SS_OPTION_ALLOW_INPUT_SCALAR_EXPANSION option, using
Masked Multiport S-Functions
If you are developing masked multiport S-function blocks whose number of ports varies based on some parameter, and want to place them in a Simulink library, you must specify that the mask modifies the appearance of the block. To do this, execute the command
at the MATLAB command prompt before saving the library, where
blockname is the full path to the block. Failure to specify that the mask modifies the appearance of the block means that an instance of the block in a model reverts to the number of ports in the library whenever you load the model or update the library link.
Level-2 MATLAB S-Function | S-Function Builder | S-Function | MATLAB Function