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 lengthssGetNumContStates(S)
. ReturnsNULL
if the S-function does not have any continuous states.
Description
Use in the simulation loop,mdlInitializeConditions
, ormdlStart
routines to get thereal_T
continuous state vector for the S-function. This vector has lengthssGetNumContStates(S)
. Typically, this vector is initialized inmdlInitializeConditions
and used inmdlOutputs
.
并出口ages
C, C++
Example
The following lines from the filecsfunc.c
show how to initialize the continuous states inmdlInitializeConditions
and calculate the state derivatives inmdlDerivatives
. This S-function is used in the modelsfcndemo_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); }