dx as output of Level 2 C-Code S-Function
Ältere Kommentare anzeigen
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];
}
Antworten (1)
Michael Proff
am 24 Jan. 2020
0 Stimmen
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.
Kategorien
Mehr zu Configure C/C++ S-Function Features finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!