'Or' statement in matlab?

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

4 个评论

which else if?
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
Image Analyst understood faster and gave you the answer...
Simran Wasu
Simran Wasu 2016-2-20
编辑:Simran Wasu 2016-2-20
use '||' for OR command (without quotes).

请先登录,再进行评论。

 采纳的回答

Image Analyst
Image Analyst 2012-9-7
编辑:Image Analyst 2012-9-7
You need two &&:
if balls == 0 && ( x > 5 || y > 7)
% run xscript
xscript();
end

5 个评论

Aadil
Aadil 2012-9-7
编辑:Aadil 2012-9-7
oh ok, can you please link me any documentation regarding && and (these line things which aren't appearing) ?
Thanks,
@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".
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.
ok thanks everyone

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by