Alternative of Code Switch and IF Else if else In Matlab

Here is the MATLAB code first. Below the code, I will discuss its problems, for which I need an alternative approach.

if((a>b) && (c>d) && (e==f) || (g<h) || (i==j))
msgbox('This is 1st','Recognize');
elseif((a>b) && (c>d) && (e==f) || (g>h) || (i~=j))
    msgbox('This is 2nd','Recognize');
elseif( (e==f) || (g<h) || (i==j))
    msgbox('This is 3rd','Recognize');
elseif((a>b) && (c>d) && (e==f))
    msgbox('This is 4th ','Recognize');
    elseif((a>b) && (c>d))
        msgbox('This is 32nd','Recognize');
msgbox('Condition not meet','Recognize');

Problems I am facing:

1. There are 32 different if else if. According to the rules, when one if or elseif becomes true, the rest will be skipped.

2. If I use only if (not else), then all will be checked individually, but it will take too much time for processing. And it may be that more than one condition becomes true at the same time.

3. Switch also works as if else if (when a case is true, the rest are ignored).

The required solution is: that all 32 conditions should be checked and the best will be executed.


You could do something like

action = 1^a + 2^b + 2^c + ...

and then use the number action for a Switch or to access a value in a cell or array (which contains your string).


 ? Alternative to if elseif in Matlab
 ? Alternative to if elseif in Matlab
 ? Alternative to if elseif in Matlab
 ? How to check a pattern in a string in matlab?
 ? Subplot using hold and elseif in matlab
 ? Matlab IF and ELSEIF loop
 ? How to give value of string to another string in matlab
 ? MATLAB: if..elseif...elseif a lot of times
 ? matlab. vectorization within if/else if/else statements
 ? matlab. vectorization within if/else if/else statements