How can I do this without using else if?:
if balls == 0 & ( x > 5 OR y > 7)
run xscript
end
Thanks,

4 Kommentare

José-Luis
José-Luis am 7 Sep. 2012
which else if?
Aadil
Aadil am 7 Sep. 2012
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:
if balls == 0 & x > 5
run xscript
elseif balls == 0 & y > 7
run xscript
end
end
José-Luis
José-Luis am 7 Sep. 2012
Image Analyst understood faster and gave you the answer...
Simran Wasu
Simran Wasu am 20 Feb. 2016
Bearbeitet: Simran Wasu am 20 Feb. 2016
use '||' for OR command (without quotes).

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Image Analyst
Image Analyst am 7 Sep. 2012
Bearbeitet: Image Analyst am 7 Sep. 2012

2 Stimmen

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

5 Kommentare

Aadil
Aadil am 7 Sep. 2012
Bearbeitet: Aadil am 7 Sep. 2012
oh ok, can you please link me any documentation regarding && and (these line things which aren't appearing) ?
Thanks,
Jan
Jan am 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
Image Analyst am 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
Aadil am 7 Sep. 2012
ok thanks everyone

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by