When I create object of a class by calling myClass* p_myClass = new myClass(); outside all the S-function method, it will work for the first run. When I run the model again, it outputs a really small number, which doesn't seem to work properly. When I put create the object and store the pointer using PWork vector inside mdlStart, it works. What is the difference? Below is my simple code to test this.
#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */ #include "simulink.c" /* MEX-file interface mechanism */ #else #include "cg_sfun.h" /* Code generation registration function */ #endif