MATLAB: Calling mex function from within Simulink

simulink

Hi,
I have been struggling to get a matlab function to compile in Simulink. I managed to compile it with the Coder and I have a mex file handy. However, in simulink, the same function does not compile using the Simulink coder. It is complaining about some dependencies which seem to be present when invoking the coder. Is there a simple path to invoke the mex file created with the Coder?
Thanks, — Octav

Best Answer

As Friedrich mentioned in his comment, MATLAB MEX-functions can be invoked from a MATLAB Function block, but they are not supported for code-generation. You will need to convert your MEX-function to an S-Function and call that using an S-Function Block. Typically it is recommended that you write a TLC file to inline the S-function in generated code, but even without a TLC file, you can generate code by checking the Support: non-inlined S-functions checkbox in the Configuration Parameters window. Note that the generated code is not very efficient for non-inlined S-functions because it needs to dispatch calls to the S-function loaded as a shared library, and passes around a large object called the SimStruct.