User`s guide
Overview of the C MEX S-Function Routines
3-27
Example: mdlProcessParameters. This example processes a string parameter that
mdlCheckParameters has verified to be of the form '+++' (where t here could
be any number of '
+'or'-' characters).
#define MDL_PROCESS_PARAMETERS /* Change to #undef to remove function */
#if defined(MDL_PROCESS_PARAMETERS) && defined(MATLAB_MEX_FILE)
static void mdlProcessParameters(SimStruct *S)
{
int_T i;
char_T *plusMinusStr;
int_T nInputPorts = ssGetNumInputPorts(S);
int_T *iwork = ssGetIWork(S);
if ((plusMinusStr=(char_T*)malloc(nInputPorts+1)) == NULL) {
ssSetErrorStatus(S,"Memory allocation error in mdlStart");
return;
}
if (mxGetString(SIGNS_PARAM(S),plusMinusStr,nInputPorts+1) != 0) {
free(plusMinusStr);
ssSetErrorStatus(S,"mxGetString error in mdlStart");
return;
}
for (i = 0; i < nInputPorts; i++) {
iwork[i] = plusMinusStr[i] == '+'? 1: -1;
}
free(plusMinusStr);
}
#endif /* MDL_PROCESS_PARAMETERS */
mdlProcessParameters is calledfrommdlStart to load the signs string priorto
the start of the simulation loop:
#define MDL_START
#if defined(MDL_START)
static void mdlStart(SimStruct *S)
{
mdlProcessParameters(S);
}
#endif /* MDL_START */
For more details on this example, see matlabroot/simulink/src/
sfun_multiport.c
Defining S-Function Block Characteristics
The sizes structure in the SimStruct stores e ss ent ial size info rmat ion about
the S-Function block, including the number of inputs, outputs, states, and
other block cha racte ris tics. T he
sizes structure is initialized in the