help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Logical indexing and Octave manual example


From: Tim Largy
Subject: Re: Logical indexing and Octave manual example
Date: Thu, 6 Mar 2008 15:06:22 -0500

>  The values are logical (true/false).  So the index selects acts as a
>  mask and selects elements that correspond to true values in the mask.
>
>  Just above the example you quote, it says
>
>   Logical values can also be used to index matrices and cell
>   arrays.  When indexing with a logical array the result will be a
>   vector containing the values corresponding to true parts of the
>   logical array.
>
>  Perhaps it should say "true elements" and/or use the word mask?
>
>  jwe
>

"Mask" is a good word, but perhaps what I needed to see was an example
driving home the fact that ordinary arrays and logical arrays are
different beasts. For example:

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

 1
 2

octave:5> idx
idx =

 1  1
 0  0

octave:6> data([1 1; 0 0])
error: invalid matrix index = 0
octave:6> data(logical([1 1; 0 0]))
ans =

 1
 2

Tim


reply via email to

[Prev in Thread] Current Thread [Next in Thread]