User`s guide

Writing Basic C MEX S-Functions
3-9
mdlOutput:
- The numerical calculation.
mdlOutputs tells S imulink to multiply the
input signal by 2.0 and place the result in the output sig nal.
- To access the input signal, use:
InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);
where uPtrs is a vector of pointers and must be accessed using:
*uPtrs[i]
For more details, see Data View of S-Functions” on page 3–19.
- To a ccess the output signal, use
real_T *y = ssGetOutputPortRealSignal(S,0);
This returns a contiguous a rray for the block’s outputs.
- The S -function loops o ver the width of the signal passing through the
block. To access the width, you can check the input or output port width.
Here the output port width was evaluated.
mdlTerminate:
- This is a mandatoryS-function routine. However, the
timestwo S-function
doesn’t need to perform any termination actions, so this routine is empty.
Atthe end ofthe S-function,specifycode thatattaches this exampleto either
Simulink or the Real-Time Workshop:
#ifdef MATLAB_MEX_FILE
#include "simulink.c"
#else
#include "cg_sfun.h"
#endif