Simulink - Embedded Matlab - Usable functions
1 view (last 30 days)
Show older comments
Hi everyone,
I need a fast SIMULINK model and I would like to use MATLAB functions. In Matlab 7.1 there are 2 possibilities to use MATLAB functions: 1. Embedded MATLAB block 2. a MATLAB function.
As I have read so far, a MATLAB function is very slow, since this block can not be totally (or not at all?) compiled and Matlab has to be executed at every single time step. With the Embedded MATLAB block, it can be fast, depending on the functions used, as I understand.
Simulink Help says: This section lists the callable functions of the Embedded MATLAB run-time function library. Functions in the Embedded MATLAB run-time library have the same name, same arguments (with limitations), and the same functionality (with limitations) as their MATLAB or Fixed-Point Toolbox counterparts, but are written in C to produce efficient embeddable generated code. If you restrict your function calls in Embedded MATLAB functions to these functions, you can use the code generated for an Embedded MATLAB function to build a stand-alone executable target that you can move to different platforms for execution
The callable functions of the Embedded MATLAB run-time function library are posted in the Simulink Help.
My questions now: 1. Did I get it right, that the speed of the embedded MATLAB block depends on the functions called within that block, i.e. if I use supported or unsupported functions (it is clear that some functions are faster and slower anyway)? 2. The list of callable functions does not include if, else, while, end and so on. Does that mean, that if I use those, the block gets slow and has to execute MATLAB during simulation?
Thanks for your support
0 Comments
Answers (2)
Kaustubha Govind
on 12 Oct 2011
1. Yes, you are right that the speed of execution of the Embedded MATLAB block depends on whether you are calling un-supported MATLAB functions from it (i.e. functions that are not on this list - caveat this list is for the latest release of MATLAB, look at the documentation in your release for the correct list - older versions may have had a smaller list). Unsupported functions need to be declared as eml.extrinsic (or coder.extrinsic) before being used - these calls are dispatched to the MATLAB interpreter and are therefore slow.
2. You are overlooking the list of MATLAB Language Features Supported for Code Generation - control statements like if/else, while/end, for/end, etc. are indeed converted into C for execution.
0 Comments
JOKY JOKE
on 13 Oct 2011
1 Comment
Kaustubha Govind
on 14 Oct 2011
Please see #2 in my previous answer for the link to the documentation page that does list if/else, while/end, for/end, etc. as supported in Embedded MATLAB blocks. So you *can* use these constructs without a slow-down.
Yes, the Embedded MATLAB block will throw an error if you attempt to use an unsupported function without declaring it using eml.extrinsic.
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!