MATLAB: Am I unable to debug an Embedded MATLAB function present in a model referenced by the root model

simulink

I have a model containing an EML function which is referenced by another model. When I run the top level model, the breakpoints in my reference model's EML function block are not hit.

Best Answer

For Simulink 7.1 (R2008a), you can run the model in "Normal" mode to be able to debug EML code.
For prior versions of Simulink, this is the expected Simulink behavior when using model references.
When the root model is simulated, it calls the compiled mex files of the referenced model . If we wish to debug the EML function present within the referenced mode, we need to simulate the model which contains the EML function. The top level model just treats the referenced model as a compiled C-function, and so the EML function block is not visible to the root model.
A possible workaround is:
1) Back up your model.
2) Copy your embedded MATLAB file into a MATLAB file and save it.
3) Temporarily replace the EML block with a MATLAB function block. Enter the name of your MATLAB file function as the function to be called by the function block.
4) Debug your code in the MATLAB file and make any changes as necesary.
5) Replace the MATLAB function block with an EML block and copy the updated MATLAB file code into the block.