MATLAB: Simulink Model Stuck Initializing

mexs-functionsimulink

I just compiled a C MEX function and am trying to create an S-Function using it. However, after entering it into the S-Function block and pressing play, the model goes into "Initializing" mode and just stays like that. I have left it on for hours with no progress whatsoever. And I have to close MATLAB in order to get it to stop. What does this mean?

Best Answer

Okay, I finally figured it out. It was actually a code issue. For one thing, I was nesting functions within mdlOutputs, which I should have known better than to do since you can't nest functions in C. Second of all, I had the block inputs redefined as inputs to the objective function:
double myfunc(unsigned n, const double *x, double *grad, void *my_func_data, double xi, double yi)
Which was overwriting the actual input values with nothing. The funny thing is in my original code I didn't have that mistake; I must have added that to the code in MATLAB on a whim while debugging and forgotten to remove it.
See attached for the fixed version.