Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

mdlProcessParameters - Process the S-function's parameters

Required

No

C Syntax

#define MDL_PROCESS_PARAMETERS
void mdlProcessParameters(SimStruct *S)

C Arguments

S

SimStruct representing an S-Function block.

M Syntax

ProcessParameters(s)

M Arguments

s

Instance of Simulink.MSFcnRunTimeBlock class representing the Level-2 M-File S-Function block.

Description

This is an optional routine that the Simulink engine calls after mdlCheckParameters changes and verifies parameters. The processing is done at the top of the simulation loop when it is safe to process the changed parameters. This function is only valid for simulation. C MEX S-functions must enclose the method in a #if defined(MATLAB_MEX_FILE) statement.

The purpose of this routine is to process newly changed parameters. An example is to cache parameter changes in work vectors. The engine does not call this routine when it is used with the Real-Time Workshop product. Therefore, if you use this routine in an S-function designed for use with the Real-Time Workshop product, you must write your S-function so that it doesn't rely on this routine. To do this, you must inline your S-function by using the Target Language Compiler. See Real-Time Workshop Target Language Compiler for information on inlining S-functions.

C Example

This example processes a string parameter that mdlCheckParameters has verified to be of the form '+++' (where there 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 called from mdlStart to load the signs string prior to the start of the simulation loop.

#define MDL_START
#if defined(MDL_START)
static void mdlStart(SimStruct *S)
{
    mdlProcessParameters(S);
}
#endif /* MDL_START */

Languages

C, C++, M

See Also

mdlCheckParameters

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS