필터 지우기
필터 지우기

Is it better to use switch block or if-else block in Simulink?

조회 수: 2 (최근 30일)
Pallanti Srinivasa Rao
Pallanti Srinivasa Rao 2017년 11월 12일
댓글: Birdman 2017년 11월 12일
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

채택된 답변

Birdman
Birdman 2017년 11월 12일
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:
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
Pallanti Srinivasa Rao
Pallanti Srinivasa Rao 2017년 11월 12일
Thank you so much. And thanks for the valuable inputs on code generation too.
Birdman
Birdman 2017년 11월 12일
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.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by