MATLAB Answers

Simulink - How to create a conditional "if" block with more than 3 conditions?

97 views (last 30 days)
Simulink - How do I create a conditional "if" block with more than 3 statements?
For example:
if(a>2)
do something
elseif (b>3)
do something else
elseif (c>4)
do something else
elseif (a<2 and c<2)
do something else
else
do default
end
What have I tried so far:
  • The default "if" block permits only 2 conditions + default.
  • I tried using the "case" but case only take one input and I need multiple inputs and 1 output (different depending on the conditions).
  4 Comments
Katarina Vuckovic
Katarina Vuckovic on 18 Sep 2019
I used the user defined function and it worked. Thank you David K.
Also, the image is very helpful and now I see how I can do it in the window.

Sign in to comment.

Accepted Answer

David K.
David K. on 18 Sep 2019
**Moved from questions to answer**
When you know the matlab code needed to do something in Simulink a Matlab Fuction Block can be added to solve the problem.
However, the IF block can also do multiple else ifs as shon below.
simulinkIFS.png

More Answers (0)

Community Treasure Hunt

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

Start Hunting!