dx as output of Level 2 C-Code S-Function

조회 수: 1 (최근 30일)
Marco Schmid
Marco Schmid 2017년 5월 3일
답변: Michael Proff 2020년 1월 24일
I'd like to have all my derivatives in my output-port. Does anybody know a trick to do that? I tried to access the dx Variables with the function ssGetdX(S) but it doesn't work. Maybe i have to create a initialize condition?
/* Function: mdlOutputs =======================================================
* Abstract:
* Define output of S-function
*/
static void mdlOutputs(SimStruct *S, int_T tid)
{
real_T *y = ssGetOutputPortRealSignal(S,0);
real_T *x = ssGetContStates(S);
real_T *dx = ssGetdX(S);
InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);
UNUSED_ARG(tid); /* not used in single tasking mode */
y[0]=dx[0];
y[1]=x[1];
y[2]=x[2];
y[3]=x[3];
}

답변 (1개)

Michael Proff
Michael Proff 2020년 1월 24일
You can but not for the first time (initial conditions) the mdlOutputs function is called.
Regarding to the documentation the mandatory mdlOutputs function is called before the optional mdlDerivatives function.
You can ignore the first time by checking the dx for NULL pointer, which it is for the first time mdlOutputs is called. However, you would have zeros for the initial conditions. To avoid that, you would have to evaluate the derivatives also for the initial conditions inside the mdlOutputs function.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by