MATLAB Compiler | ![]() ![]() |
Simulink Specific Options
By using Simulink specific options with the MATLAB Compiler, you can generate an S-function that is compatible with the S-Function block. The Simulink specific options are -S
, -u
, and -y
. Using any of these options with the MATLAB Compiler causes it to generate code that is compatible with Simulink.
Using the -S Option
The simplest S-function that the MATLAB Compiler can generate is one with a dynamically sized number of inputs and outputs. That is, you can pass any number of inputs and outputs in or out of the S-function. Both the MATLAB Fcn block and the S-Function block are single-input, single-output blocks. Only one line can be connected to the input or output of these blocks. However, each line may be a vector signal, essentially giving these blocks multi-input, multi-output capability. To generate a C language S-function of this type from an M-file, use the -S
option:
The result is an S-function described in the following files:
mfilename.c mfilename.h mfilename_simulink.c mfilename.ext (whereext
is the MEX-file extension for your platform, e.g.,dll
for Windows)
Using the -u and -y Options
Using the -S
option by itself will generate code suitable for most general applications. However, if you would like to exert more control over the number of valid inputs or outputs for your function, you should use the -u
and/or -y
options. These options specifically set the number of inputs (u
) and the number of outputs (y
) for your function. If either -u
or -y
is omitted, the respective input or output will be dynamically sized:
In the above line, the S-function will be generated with an input vector whose width is 1 and an output vector whose with is 2. If you were to connect the referencing S-Function block to signals that do not correspond to the correct number of inputs or outputs, Simulink will generate an error when the simulation starts.
Note
The MATLAB Compiler -S option does not support the passing of parameters, which is normally available with Simulink S-functions.
|
![]() | Generating Simulink S-Functions | Specifying S-Function Characteristics | ![]() |