Is it better to use switch block or if-else block in Simulink?
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Pallanti Srinivasa Rao
am 12 Nov. 2017
Kommentiert: Birdman
am 12 Nov. 2017
Hi,
I have the following set of code in Matlab. I want to know, which is the best way to implement this code in Simulink (using switch block or if-else block!?).
If a > 0 c = m + n; else c = m - n; end
Thanks
0 Kommentare
Akzeptierte Antwort
Birdman
am 12 Nov. 2017
Well, in this kind of situations, it is better to use MATLAB Function block in Simulink since in case of code generation, MATLAB Functions are compatible for C code generation and several functions used in command line also become usable in Simulink by the help of MATLAB Functions. See the links below:
https://www.mathworks.com/help/simulink/slref/matlabfunction.html https://www.mathworks.com/help/simulink/ug/functions-supported-for-code-generation-alphabetical-list.html
Also, you may write a function for your algorithm as follows:
function c=SWITCH(a,m,n)
c=0;%initializing
if(a>0)
c=m+n;
else
c=m-n;
end
end
where you have three inputs and one output. Hope this helps.
6 Kommentare
Birdman
am 12 Nov. 2017
You are welcome. If my answer solves the issue, then accept the answer so that other people having the same problem will know there is a working solution.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Simulink Functions finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!