Hi,
I'm using octave 3.0.1 under Ubuntu 9.04 (64-bit).
I'd like to increment certain elements of a vector whose indices are
given
in another vector, but I get undesired results. Say
octave:50> a=zeros(1,3);
octave:51> b=[1 2 1 1 2 1];
octave:52> a(b)++;
octave:53> a
a =
1 1 0
However, I would expect (i.e. I'd like) to obtain
a =
4 2 0
as the index 1 is found 4 times in b, index 2 is found 2 times in b,
and
index 3 is not in b.
Using pre-increment, i.e. ++a(b), produces the same result.
I'm now using an explicit loop (for) to do this, as follows:
octave:54> a=zeros(1,3);
octave:55> for i=[1:length(b)]
a(b(i))++;
endfor
octave:56> a
a =
4 2 0
However, I'd like to get rid of it since I want to do this over very
large
(1e6 elements) vectors and in this case it takes a lot of time,
whereas
simple operations over such large vectors are quite fast.
Is it possible to do what I intend in a fast way?