﻿ Alternative of Code Switch and IF Else if else In Matlab

# 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');
else
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.

``````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).