Executing full MATLAB code within Simulink Blocks

An easy way to execute complicated functions in Simulink is to use the Embedded MATLAB Function block. When you insert one of these blocks it creates a MATLAB file that is contained within the Simulink model block. The issue with this block is that only a subset of the full MATLAB language is available within an Embedded block. The simple solution to this problem is the function eml.extrinsic which sets certain functions to execute externally.


[outputa outputb] = myfunction(inputa, inputb);

The function names within the extrinsic call will be set to run within MATLAB instead of Simulink. Now functions like tf and ss can be used!

Another Embedded MATLAB tip is to use ‘*1i’ to represent complex numbers. (This is mentioned in the MATLAB documentation but looks like ‘li’.)



2 thoughts on “Executing full MATLAB code within Simulink Blocks

  1. Hi,
    I have lot of matlab function in separate files. Can i use “eml.extrinsic” to only one function or need to use this for all function ? can you help?

    • The example I showed in this post was just for a single function, so I think it should work for you. I don’t actually have a copy of Simulink to test it myself anymore. If you have trouble maybe check that your .m files are in the same directory so there’s no path issues. Good luck!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s