Speed comparison S-Function - Simulink blocks

조회 수: 10 (최근 30일)
Thiago Marinho
Thiago Marinho 2011년 7월 2일
Hi!
I have simulink Level 2 M File S-Function block and I have also a subsystem with simulink blocks written to do exactly the same thing, they solve the same differential equations. The subsytem runs much faster thant the S-function block.
How should the performance of a S-Function block compare to a fully simulink based model? In this case I am talking about a Level 2 M file S Function.
Thank you for your answers.

채택된 답변

Guy Rouleau
Guy Rouleau 2011년 7월 2일
MATLAB-file s-functions are interpreted by the MATLAB engine. Core blocks are compiled.
As said on wikipedia:
"The main disadvantage of interpreting is a much slower speed of program execution"
If you want to write MATLAB code that runs fast, you can use the MATLAB Function Block (previously called Embedded MATLAB Function block). Or you also have the option to write a C-Mex s-function.
I wrote posts about including MATLAB code in a simulation:
and about speeding up a simulation:

추가 답변 (1개)

Thiago Marinho
Thiago Marinho 2011년 7월 3일
Thank you! That was of great help.
Although Level-2 S-functions are slower I just cannot use Matalab function block for my purposes.
Is there a way to compile the m-file s-function block or do I have to write a C-Mex s-function?
How will the C-Mex s-function compare to a model made only out of simulink core blocks?
  댓글 수: 1
Kaustubha Govind
Kaustubha Govind 2011년 7월 5일
Thiago: Unfortunately the only way to get performance comparable with core blocks with MATLAB code is to use the MATLAB Function block. The only alternative currently is to write a C-MEX S-function, whose performance should be comparable to that of core blocks.

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

Community Treasure Hunt

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

Start Hunting!

Translated by