I am having trouble using unique and histc commands for the following task, anyone knows how the solve it?

1 view (last 30 days)
A =
1 5
2 7
2 9
3 5
4 4
5 8
5 4
5 6
6 2
First column refers to the values and the second one refers to the occurances. How it is possible to convert this matrix to the following
A =
1 5
2 16
3 5
4 4
5 18
6 2
thanks in advance

Answers (1)

Guillaume
Guillaume on 15 Apr 2015
The command you need for this is |accumarray in it is simplest form:
Anew = [(1:max(A:, 1)' accumarray(A(:, 1), A(:, 2))]

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!