Asked by Aadil
on 7 Sep 2012

How can I do this without using else if?:

if balls == 0 & ( x > 5 OR y > 7) run xscript end

Thanks,

*No products are associated with this question.*

Answer by Image Analyst
on 7 Sep 2012

Edited by Image Analyst
on 7 Sep 2012

Accepted answer

You need two &&:

if balls == 0 && ( x > 5 || y > 7) % run xscript xscript(); end

Show 2 older comments

Jan Simon
on 7 Sep 2012

@Aadil: Simply ask Google for "Matlab &&" and you weill immediate get: http://www.mathworks.de/help/techdoc/ref/logicaloperatorsshortcircuit.html, which refers to http://www.mathworks.de/help/techdoc/ref/logicaloperatorselementwise.html. Or type "help or".

Image Analyst
on 7 Sep 2012

I've seen that before - where the vertical lines don't appear. However I can't reproduce anymore. For me | appears both in regular text, and code formatted text. By the way, I edited by answer to change "run xscript" to be just "xscript" since the "run" command like you had is not needed.

Aadil
on 7 Sep 2012

ok thanks everyone

Log in to comment.

Related Content

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

Learn moreOpportunities for recent engineering grads.

Apply Today
## 4 Comments

## José-Luis (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/47600-or-statement-in-matlab#comment_98082

which else if?

## Aadil (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/47600-or-statement-in-matlab#comment_98085

what I meant is that I can use else if to do the above, but how can I avoid having to write the commands twice like this:

## José-Luis (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/47600-or-statement-in-matlab#comment_98087

Image Analyst understood faster and gave you the answer...

## Simran Wasu (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/47600-or-statement-in-matlab#comment_344137

use '||' for OR command (without quotes).

Log in to comment.