ssGetContStates - Get a block's continuous states
Syntax
real_T *ssGetContStates(SimStruct *S)
Arguments
- S
SimStruct representing an S-Function block.
Returns
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.
Description
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.
Languages
C, C++
Example
The following lines from the file matlabroottoolbox/simulink/simdemos/simfeatures/src/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);
}See Also
ssGetNumContStates, ssGetRealDiscStates, ssGetdX, mdlInitializeConditions, mdlStart
 | ssGetBlockReduction | | ssGetCurrentInputPortDimensions |  |
Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
Get this Simulink Kit