User`s guide

3 Writing S-Functions As C-MEX files
3-4
Writing Basic C MEX S-Functions
This secti on d iscusses bas ic C MEX S-f unctions, where basic means an
S-function that contains only the required S-function routines. However, the
contents of the routines can be as complex as you like. You have the freedomto
place any logic in S-function routines a s long as the routines conform to their
required formats. This section prese nts a basic C MEX S- function by showing
how to implement an S-function that takes i ts input and multiplies it by two
(see
matlabroot/simulink/src/timestwo.c).
Inthefollowingmodel,the
timestwo S-functionisusedtodouble theamplitude
of a sine wave and plot it in a sco pe:
Within the block dialog fo r the S-function,
timestwo has been s pecified as the
name; the parameters field i s empty.
The
timestwo S-function contains the S-function routines shown in this figure:
Start of simulation
mdlInitializeSizes
mdlInitializeSampleTimes
mdlOutputs
mdlTerminate
Simulatio n
loop
Initialization