Simulink - Embedded Matlab - Usable functions

조회 수: 1 (최근 30일)
JOKY JOKE
JOKY JOKE 2011년 10월 12일
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

답변 (2개)

Kaustubha Govind
Kaustubha Govind 2011년 10월 12일
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.

JOKY JOKE
JOKY JOKE 2011년 10월 13일
Hi,
I am using MATLAB 7.1 and the list (HELP) of supported functions for embedded MATLAB blocks does not include Program control statements if, switch, for, while, end... Does that mean, that, in terms of speeding up my model, I should not use them or are they just not explicitly mentioned?
If I use an unsupported function, does Simulink tell me that by showing an error message or how do I find out (besides the list), if I am using supported or unsupported functions?
  댓글 수: 1
Kaustubha Govind
Kaustubha Govind 2011년 10월 14일
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.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by