MATLAB: Summing with respect to values within variable instead of rows, columns, or equal windows

summing with respect to values within variables

I have a variable with a similar structure to the following but with many more rows:
a=
1 0.3
1 0.1
2 0.7
2 0.6
2 0.3
2 0.9
3 0.5
4 0.8
4 0.1
5 0.1
5 0.9
5 0.4
Say I want sums of column 2 with respect to each scalar (eg. 1, 2…5) so that I would get a new variable like this:
aa=
1 0.4
2 2.5
3 0.5
4 0.9
5 1.4
I have not found how to sum anything but rows and columns, so how should I go about summing based on values within a variable?

Best Answer

a=[
1 0.3
1 0.1
2 0.7
2 0.6
2 0.3
2 0.9
3 0.5
4 0.8
4 0.1
5 0.1
5 0.9
5 0.4]
uv = unique(a(:,1),'stable');
sidx = accumarray(a(:,1),a(:,2));
[uv sidx]
accumarray() to the rescue!