Target Language Compiler Function Conventions
You can find examples using these functions in
and matlabroot
/toolbox/simulink/blocks/tlc_c
.
The corresponding MEX S-function source code is located in matlabroot
/toolbox/simulink/sfuntemplates/tlc_c
or matlabroot
/simulink/src
.
MATLAB® file S-functions and the MEX-file executables (for example,
matlabroot
/toolbox/simulink/simdemos/simfeatures/src
) are located in
sfunction
.mex*
or
matlabroot
/toolbox/simulink/blocks
.
Clicking one of the preceding folder names changes to that
folder in MATLAB and shows the folder contents in the MATLAB Current Folder browser.matlabroot
/toolbox/simulink/simdemos/simfeatures
Common Function Arguments
Several functions take similar or identical arguments. To simplify the reference pages, some of these arguments are documented in detail here instead of in the reference pages.
Argument | Description |
---|---|
Refers to an input or output port index, starting at 0. For example, the first input port of an S-function is 0. | |
User control variable. This is an advanced feature that overrides the
| |
Loop control variable. This is generally generated by the
| |
Signal index. Sometimes referred to as the signal element index. When
accessing specific elements of an input or output signal directly, the call to the
various library routines should have Most functions that take a
Use the Functions that accept the three arguments
| |
| Parameter index. Sometimes referred to as the parameter element index.
The handling of this parameter is very similar to |
State index. Sometimes referred to as the state vector element index. It
must evaluate to an integer where the first element starts at
|
Overloading sigIdx
The signal index (sigIdx
sometimes written as idx
)
can be overloaded when passed to most library functions. Suppose you are interested in
element 3 of a signal, and ucv=""
, lcv=""
. The
following table shows
Values of
sigIdx
Whether the signal being referenced is complex
What the function that uses
sigIdx
returnsAn example of a returned variable
Data type of the returned variable
Note that “container” in the following table refers to the object that
encapsulates both the real and imaginary parts of the number, e.g.,
creal_T
, defined in tmwtypes.h
.
sigIdx | Complex | Function Returns | Example | Data Type |
---|---|---|---|---|
"re3" | Yes | Real part of element 3 |
|
|
"im3" | Yes | Imaginary part of element 3 |
|
|
"3" | Yes | Complex container of element 3 |
|
|
3 | Yes | Complex container of element 3 |
|
|
"re3" | No | Element 3 |
|
|
"im3" | No |
| N/A | N/A |
"3" | No | Element 3 |
|
|
3 | No | Element 3 |
|
|
Now suppose the following:
You are interested in element 3 of a signal.
(
ucv = "i"
ANDlcv == ""
) OR (ucv = ""
ANDlcv = "i"
).
The following table shows values of idx
, whether the signal is
complex, and what the function that uses idx
returns.
sigIdx | Complex | Function Returns |
---|---|---|
"re3" | Yes | Real part of element |
"im3" | Yes | Imaginary part of element |
"3" | Yes | Complex container of element |
3 | Yes | Complex container of element |
"re3" | No | Element |
"im3" | No |
|
"3" | No | Element |
3 | No | Element |
Notes
The vector index is added only for wide signals.
If
ucv
is not an empty string (""
), thenucv
is used instead ofsigIdx
in the above examples and bothlcv
andsigIdx
are ignored.If
ucv
is empty butlcv
is not empty, then the function returns"&y%<portIdx>[%<lcv>]"
andsigIdx
is ignored.It is assumed that the roller has declared and initialized the variables accessed inside the roller. The variables accessed inside the roller should be specified using
rollVars
as the argument to the%roll
directive.