dx as output of Level 2 C-Code S-Function
이전 댓글 표시
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
2020년 1월 24일
0 개 추천
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.
카테고리
도움말 센터 및 File Exchange에서 Configure C/C++ S-Function Features에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!