User`s guide
Overview of the C MEX S-Function Routines
3-49
Simulink will call this routine in two places:
• At the start of simulation
• If it is present in an enabled subsystem configured to reset states. In this
case, Simulink will call
mdlInitializeConditions when the enabled
subsystem restarts execution to reset the states.
You can use the
ssIsFirstInitCond(S) macro to determine whether the
current call is the first to
mdlInitializeConditions.
The synopsis is:
#define MDL_INITIALIZE_CONDITIONS /* Change to #undef to remove function */
#if defined(MDL_INITIALIZE_CONDITIONS)
static void mdlInitializeConditions(SimStruct *S)
{
}
#endif /* MDL_INITIALIZE_CONDITIONS */
This example is an S-function with both continuous and discrete states; it
initializes both sets of states to 1.0:
#define MDL_INITIALIZE_CONDITIONS /* Change to #undef to remove function */
#if defined(MDL_INITIALIZE_CONDITIONS)
static void mdlInitializeConditions(SimStruct *S)
{
int i;
real_T *xcont = ssGetContStates(S);
int_T nCStates = ssGetNumContStates(S);
real_T *xdisc = ssGetRealDiscStates(S);
int_T nDStates = ssGetNumDiscStates(S);
for (i = 0; i < nCStates; i++) {
*xcont++ = 1.0;
}
for (i = 0; i < nDStates; i++) {
*xdisc++ = 1.0;
}
}
#endif /* MDL_INITIALIZE_CONDITIONS */
For another example which initializes only the continuous states, see
matlabroot/simulink/src/resetint.c.