| Contents | Index |
real_T *ssGetContStates(SimStruct *S)
A pointer (real_T *) to the continuous state vector as an array of length ssGetNumContStates(S). Returns NULL if the S-function does not have any continuous states.
Use in the simulation loop, mdlInitializeConditions, or mdlStart routines to get the real_T continuous state vector for the S-function. This vector has length ssGetNumContStates(S). Typically, this vector is initialized in mdlInitializeConditions and used in mdlOutputs.
C, C++
The following lines from the file csfunc.c show how to initialize the continuous states in mdlInitializeConditions and calculate the state derivatives in mdlDerivatives. This S-function is used in the model sfcndemo_csfunc.mdl.
static void mdlInitializeConditions(SimStruct *S)
{
real_T *x0 = ssGetContStates(S);
int_T lp;
for (lp=0;lp<2;lp++) {
*x0++=0.0;
}
}
static void mdlDerivatives(SimStruct *S)
{
real_T *dx = ssGetdX(S);
real_T *x = ssGetContStates(S);
InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);
/* xdot = Ax + Bu */
dx[0]=A[0][0]*x[0]+A[1][1]*x[1]+B[0][0]*U(0)+B[0][1]*U(1);
dx[1]=A[1][0]*x[0]+A[1][1]*x[1]+B[1][0]*U(0)+B[1][1]*U(1);
}ssGetNumContStates, ssGetRealDiscStates, ssGetdX, mdlInitializeConditions, mdlStart

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |