User`s guide
3 Writing S-Functions As C-MEX files
3-44
Work vectors have several advantages:
• Instance specific storage for block variables
• Integer, real, pointer, and general data types
• Elimination of static and global variables and the associated multiple
instance pr oblems
Forexample, supposeyou’d liket o track theprevious value ofeach inputsignal
element entering input port 1 of your S-function. Either the discrete-state
vector or the real-work vector could be used for this, depending upon whether
thepreviousv aluei sconsideredadiscrete state(thatis,compare theunitdelay
andthe memoryblock). Ifyou do notwant theprevious valueto be loggedwhen
states are saved, use the real-work vector,
rwork.Todothis,in
mdlInitializeSizes specify the length of this vector by using ssSetNumRWork.
Then in either
mdlStart or mdlInitializeConditions, initialize the rwork
vector, ssGetRWork.InmdlOutputs, you can retrieve the previous inputs by
using
ssGetRWork.InmdlUpdate, update the previousvalue of the rwork vector
by using
ssGetInputPortRealSignalPtrs.
Use the macros in this table to specify the length of the work vectors for each
instance of your S-function in
mdlInitializeSizes.
Table 3-4: Macros Used in Specifying Vector Widths
Macro Description
ssSetNumContStates
Width of the continuous-state vector
ssSetNumDiscStates
Width of the discrete-state vector
ssSetNumRWork
Width of the real-work vector
ssSetNumIWork
Width of the integer-work vector
ssSetNumPWork
Width of the pointer-work vector
ssSetNumModes
Width of t he mode-work vector
ssSetNumnonsampledZCs
Width of the nonsampled zero-crossing
vector