From: Aditya Sundar on
Hello sir,

Could you just tell me how to rite multiple variables in if condition in matlab, one's could you just check below code

if val1 == 4 || val1 == 5 || val1 == 0 && val2 == 1 && val3 == 6 || val3 == 2 && val4 == 1 && val5 >= 25 && val5 <= 32 || val5 >= 120 && val5 <= 130 && val6 == 1
at = 4;
end;


i am waiting for your solution, kindly help me

thank you
From: Jan Simon on
Dear Aditya!

> Could you just tell me how to rite multiple variables in if condition in matlab, one's could you just check below code
>
> if val1 == 4 || val1 == 5 || val1 == 0 && val2 == 1 && val3 == 6 || val3 == 2 && val4 == 1 && val5 >= 25 && val5 <= 32 || val5 >= 120 && val5 <= 130 && val6 == 1
> at = 4;
> end;
>
> i am waiting for your solution, kindly help me

I do not see the problem, so I cannot suggest a solution. The shown code looks ok. You do not need a semicolon after ther end, but this is no error.

Kind regards, Jan
From: Rune Allnor on
On 12 Mar, 10:43, "Aditya Sundar" <a...(a)anits.com> wrote:
> Hello sir,
>
>  Could you just tell me how to rite multiple variables in if condition in matlab, one's could you just check below code
>
> if val1 == 4 || val1 == 5 || val1 == 0 && val2 == 1 && val3 == 6 || val3 == 2 && val4 == 1 && val5 >= 25 && val5 <= 32 || val5 >= 120 && val5 <= 130 && val6 == 1
>            at = 4;
>        end;
>
> i am waiting for your solution, kindly help me

You would want to group the test, just to make sure both
you and the matlab interpreter keeps track:

if (val1 == 4) || (val1 == 5) || (val1 == 0) && (val2 == 1)

Looking at the sequence of tests, you need to group them
into composite test, using parentheses, to make sense of
the stuff.

Since the tests are not grouped, the sequence

(val5 >= 25) && (val5 <= 32) || (val5 >= 120) && (val5 <= 130)

almost certainly does *not* do what you think it does.
It might make sense if you group the tests as

((val5 >= 25) && (val5 <= 32)) || ((val5 >= 120) && (val5 <= 130))

but it's impossible to say without knowing what you are up to.

And no! *Don't* start writing down what you are up to for
people here to try and make sense of! Your explanation will
only be comprehensable to other people than yourself if you
manage to write it detailed enough to set up the logical
expression yourself - in which case you could just as well
set up the logical expression yourself.

Instead, go have a chat with your boss or supervisor about
how to set up the logical expressions from your stated problem.

Rune