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

matlab, octave

Solution

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.

Problem

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?

Original source