Writing equations in MATLAB function vs using Simulink Blocks
31 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
回答 (3 件)
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
0 件のコメント
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.
0 件のコメント
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 ... :).
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で General Applications についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!