简体   繁体   English

为什么&&运算符看起来不适用于Matlab / Octave?

[英]Why does the && operator not appear to work in Matlab/Octave?

I'm playing around with some slightly modified Euler problems. 我正在玩一些略微修改的欧拉问题。 The following code: 以下代码:

a=(0:1:999);
b=a(mod(a,5) == 0)

Appears to do the right thing. 看起来做对了。 However with a slight modification: 但稍作修改:

a=(0:1:999);
b=a(mod(a,5) == 0 && mod(a,3) == 0)

I get 我明白了

b=[](0x0)

What is happening here? 这里发生了什么?

You want & instead of && 你想要&而不是&&

The & operator performs an element-by-element AND between matrices, while the && operator performs a short-circuit AND between scalar values. &运算符在矩阵之间执行逐元素AND,而&&运算符在标量值之间执行短路AND。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM