User`s guide
4 Guidelines for Writing C MEX S-Functions
4-18
Fully Inlined S-Functions
Continuing the example of the previous section, you could eliminate the ca ll to
my_alg entirely by specifying the explicit code (i.e., 2.0*u)inwrapsfcn.tlc.
This is referred to as a fully inlined S-function. While this can improve
performance,if your C code is large this may be a lengthytask. Inaddition,you
now have to maintain your algorithm in two places, the C S-function itself and
the corresponding TLC file. However the performance gains may outweigh the
disadvantages. To inline the algorithm used in this example, in the
Outputs
sectionofyourwrapsfcn.tlc file, instead of writing
%<y> = my_alg(%<u>);
use:
%<y> = 2.0 * %<u>;
This is the code produced in MdlOutputs:
void MdlOutputs(int_T tid)
{
/* Sin Block: <Root>/Sin */
rtB.Sin = rtP.Sin.Amplitude *
sin(rtP.Sin.Frequency * ssGetT(rtS) + rtP.Sin.Phase);
/* S-Function Block: <Root>/S-Function */
rtB.S_Function = 2.0 * rtB.Sin;
/* Outport Block: <Root>/Out */
rtY.Out = rtB.S_Function;
}
The Target Language Compiler has replaced the call to my_alg with the
algorithm itself.
Multiport S-Function Example
A more advanced multiport inline d S- f unctio n example exis ts in
matlabroot/simulink/src/sfun_multiport.c and
matlabroot/toolbox/simulink/blocks/sfun_multiport.tlc.This
S-function demonst rateshow to create a fu lly inlined T L C file for an S-function
This is the explicit
embedding o f the
algorithm.