Logical indexing and Octave manual example

Tim Largy tim.largy at gmail.com
Wed Mar 5 18:02:42 CST 2008


I'm having trouble understanding an example in section 4.4 "Logical
Values" of the Octave manual
(http://www.gnu.org/software/octave/doc/interpreter/Logical-Values.html#Logical-Values).
The manual has:

     data = [ 1, 2; 3, 4 ];
     idx = (data <= 2);
     data(idx)
          => ans = [ 1; 4 ]

However my Octave version 2.1.73 (i686-pc-cygwin) returns a different result:

    octave:72>  data = [ 1, 2; 3, 4 ];
    octave:73>  idx = (data <= 2);
    octave:74>  data(idx)
    ans =

       1
       2

In neither case can I understand the underlying logic. The value of
idx is [1, 1; 0, 0]. What rules determine how a matrix such as this is
used in logical indexing?

Regards,

Tim Largy


More information about the Help-octave mailing list