Matlab S-Functions:在哪里使用 ssSetPWorkValue()?
Matlab 的 ssSetPWorkValue() 不能在 S-Function 的 mdlInitializeSizes 函数中使用。这是因为 mdlInitializeSizes 函数在 S-Function 的工作向量分配之前被调用。
在 mdlInitializeSizes() 中使用它会导致段错误,从而导致 Matlab/Simulink 崩溃。
使用 ssSetPWorkValue() 的正确位置是在 mdlStart 函数中。此函数在工作向量分配之后被调用,是你可以安全使用 ssSetPWorkValue() 的第一个函数。
sssetpwork_example.cpp
#define MDL_START
static void mdlStart(SimStruct *S)
{
// Allocate memory for the pointer work vector
ssSetPWorkValue(S, 0, new MyDataStructure());
}Check out similar posts by category:
Matlab/Simulink
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow