Logical indexing and Octave manual example
Tim Largy
tim.largy at gmail.com
Thu Mar 6 14:06:22 CST 2008
> 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
More information about the Help-octave
mailing list