ssGetContStates
Get a block's continuous states
Syntax
real_T *ssGetContStates(SimStruct *S)
Arguments
S
SimStruct that represents 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++
Examples
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
.
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); }
Version History
Introduced before R2006a