I am looking for a way to do multiple sums simultaneously and as fast as possible. Suppose
a = [3 4 1 9 8 3 5];
indices = [1 1 2 1 2 1 2];
Then, the result should be a 1x2 array, say, sumz
with
sumz = [19 14];
In other words, I sum every element of a
with index 1, and put the result to sumz(1).
Then, I sum every element of a
with index 2, and put the result to sumz(2).
and so on.
I know how to do this using for
loops, find
, etc. What I am looking for is a fast code.