Writing equations in MATLAB function vs using Simulink Blocks

조회 수: 26 (최근 30일)
Gibin Joe Zachariah
Gibin Joe Zachariah 2019년 2월 8일
답변: Sulaymon Eshkabilov 2019년 5월 4일
What are the pros and cons of writing complex mathematical equations in embedded MATLAB function in Simulink vs creating the same equation using the Simulink blocks? Writing in MATLAB function block makes it easier to read and also to edit in future but am I losing performance if I do not use the Simulink math blocks?

답변 (3개)

Prasanth Sunkara
Prasanth Sunkara 2019년 2월 12일
Hello Gibin,
As you mentioned the equations were slightly "complex", I would presonally prefer using the MATLAB Fcn. With that said there wont be any major significant performance issues using MATLAB Fcn block. In fact MATLAB Fcn block supports generating efficient C/C++ code for your custom algorithms.
You may try implementing the same using basic Simuink blocks with the above mentioned benefits, but I am afraid you may run into some real implementation/debugging issues when you scale up your mathematical equations.
Thanks,
Prasanth

Raj
Raj 2019년 2월 12일
Hi,
I am not sure based on what you said "Writing in MATLAB function block makes it easier to read and also to edit in future". The prime reason for wide usage and popularity of Model based design using Simulink is that it makes algorithms easier to read, debug, modify and maintain commonality. So using simulink blocks definitely has an edge over writing equations manually. However, in my applications, I have found that many Simulink blocks like switch, if-else etc create problems during autocode generation. Simple blocks like "divide" are not robust to handle situations like "divide by zero" condition and can cause havoc in safety critical applications. Using your own mathematical equation gives you a lot of flexibility to add tolerances and robustness.
So all in all both ways have their own plus and minus. I would recommend you to pick a method based on your application and judgement.

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019년 5월 4일
Hi,
One of the most common practice that I take very often to reduce the number of blocks in my Simulink models instead of [MATLAB Fcn] is [MATLAB Interpreted Fcn] (with [Mux] block for signal re-routing) that is much faster than [MATLAB Fcn]. Moreover, the used expressions via this block are clear and easier to edit rather than many substitute blocks. in fact, sometimes if the expression gets large, a pen and paper will be needed though ... :).

카테고리

Help CenterFile Exchange에서 General Applications에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by