简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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