Counting the same rows of 2D matrix

Viewed 66

I have a two column matrix. I need to make it three column, where the third column shows the number of appearance of the first two as a row in the input matrix.

Basically: Input

[1 1;
 1 1;
 1 2;
 1 2;
 1 3]

Desired output:

[1 1 2;
 1 2 2;
 1 3 1]

I know already that a proper combination of accumarray and unique should do the charm. I just don't know how to properly combine them.

2 Answers
Related