MATLAB Answers


Formula if with few statements

Asked by ZK
on 25 Apr 2013


I would like to create a multiple statement in loop if containing an 'or' and 'and'. Is this possible to have a few && and 'or' in one statement? Like:

if A>2 && [(B1>Z && B2<Z) or (C1>Z && C2<Z)]





No products are associated with this question.

1 Answer

Answer by Jan Simon
on 25 Apr 2013
Edited by Jan Simon
on 25 Apr 2013
 Accepted answer

While the combination of && and || works properly, creating a vector by the square brackets is most likely not wanted.

if A>2 && ((B1>Z && B2<Z) || (C1>Z && C2<Z))

Note that the variables must be scalar for && and ||, otherwise use and() or or(), or the eqivalent & and | operators.

  1 Comment

on 25 Apr 2013

Thanks for tips, working fine.

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!