Why my level 2 s function runs very slow when the simulink is about taking the first step of integration?
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Husni Rois Ali
am 18 Okt. 2017
Kommentiert: Birdman
am 19 Okt. 2017
Hi Guys
I implemented a block on level 2 s-function (implemented in m file) that does the same job as the built-in state-space function. When I compared the result, they produced the same result. However when I compared the elapsed time I noticed that my s function run slower than simulink build in block (in particular if the size of systems is very large (4000 states)). I noticed that the long simulation time occurs before simulink taking the first step of integration. After the first step, it run at comparable speed to state-space build in block. I realized it may be caused by the inefficiency in implementation. But any other reason for this?
0 Kommentare
Akzeptierte Antwort
Birdman
am 18 Okt. 2017
In the generated code, Level 2 S-function is called upon a pointer called SimStruct, which is used to call the output function of the system. Therefore, this situation slows down the application. To get rid of this, you can inline the S-function by either using S-Function Builder in Simulink from User Defined Functions library, or you can write a tlc file for your S-function by hand which is harder and requires more effort. For detailed information and documentation, please see the following links.
4 Kommentare
Birdman
am 19 Okt. 2017
If you want to use matlab functions, you can embed them in a MATLAB Function in Simulink. You don't have to use them in S-function. The working principle of s-function is little bit different. I suggest you to read some documentation.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Simulink Coder finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!