Mon 04 Jun 2012 06:59:20 AM UTC, comment #3:
Hello,
I just found some time to fix the documentation concerning boolean indexing, and wondered if the following is intended behaviour:
octave:44> a=rand(5)
a =
0.590252 0.785107 0.789109 0.973847 0.037473
0.720128 0.552948 0.529387 0.712228 0.285633
0.097387 0.498243 0.368774 0.341973 0.272160
0.302804 0.645076 0.383922 0.550020 0.883258
0.181661 0.969068 0.376169 0.458497 0.294898
octave:45> b=a(1:3,1:3)>0.5
b =
1 1 1
1 1 1
0 0 0
octave:46> a(b)
ans =
0.59025
0.72013
0.30280
0.18166
0.55295
0.49824
octave:47> a(1:rows(b),1:columns(b))(b)
ans =
0.59025
0.72013
0.78511
0.55295
0.78911
0.52939
octave:48> a(rand(7)>0.5)
error: A(I): index out of bounds; value 48 out of bound 25
octave:48> a(-rand(7)>0.5)
ans = [](0x1)
So, what we get in more than one dimension is vec(<array>)(find(vec(<boolean>))), which is OK, and seems to be the only way to go for equally sized arrays and boolean indices, but we get index errors only for out of bounds true indices, and puzzling results without a warning when the indexing array is smaller than the indexed array.
Is this really what we want?
Alex
|