User`s guide
ii Contents
3
Writing S-Functions As C-MEX files
Introduction .......................................... 3-2
Writing Basic C M EX S-Functions ...................... 3-4
Creating More Complex C MEX S-Functions ............ 3-10
StatementsRequiredattheTopofS-Functions ........... 3-10
Statements Required at the Bottom of S-Functions . . . . . . . . 3-11
Conditionally Compiling S-Functions . . . ................. 3-12
ErrorHandling...................................... 3-12
Overview of the C MEX S-Function Routines ........... 3-15
DataViewofS-Functions ............................. 3-19
CheckingandProcessingS-FunctionParameters.......... 3-22
ParameterChanges .................................. 3-23
DefiningS-FunctionBlockCharacteristics ............... 3-27
Configuring Input and Output Port Properties . . . . . . . . . . . . 3-32
Setting Sample Times for C MEX S-Functions . . . . . . . . . . . . 3-36
ConfiguringWorkVectors ............................. 3-43
MemoryAllocation................................... 3-47
S-FunctionInitialization .............................. 3-48
S-Function Routines Cal led During S imulat ion . . . . . . . . . . . 3-50
UsingS-FunctionsWiththeReal-TimeWorkshop ......... 3-53
Examples of C MEX-File S-Function Blocks ............. 3-56
Example-ContinuousStateS-Function ................. 3-56
Example-DiscreteStateS-Function .................... 3-61
Example-HybridSystemS-Functions................... 3-65
Example-VariableStepS-Function..................... 3-68
Example-ZeroCrossingS-Function .................... 3-73
Example - Time Varying Continuous Transfer Function . . . . 3-84