MATLAB: How to integrate non-code generation capable functions into a MATLAB block in Simulink 7.7 (R2011a)

simulink

I want to make some function calls to non-code generation capable functions in my MATLAB block in my model in Simulink 7.7 (R2011a). I thought that I can do this by using the CODER.EXTRINSIC declaration, but when I do this, I still get various error messages. As an example, in triscatteredinterp_simulink_nogood.mdl, the following error occurs if I create an object 'F' via the TRISCATTEREDINTERP function (which was declared to be extrinsic), and then try to access 'F':
Subscripting into an mxArray is not supported.
Function 'Embedded MATLAB Function' (#83.277.285), line 18, column 6:
"F(qx,qy)"
Launch diagnostic report.

Best Answer

When you use EML.EXTRINSIC for a function, you instruct the Embedded MATLAB subset not to compile or generate code for that function, and instead the software dispatches these functions to MATLAB for execution. The key is to make code in the actual Embedded MATLAB block in the model a simple wrapper that calls a secondary .m file, and then to declare that entire secondary .m file to be extrinsic. Thus you avoid the general requirement that the code inside of the EML block needs to support code generation.
An example of this procedure can be seen in 'triscatteredinterp_simulink_good.mdl' attached to this solution.