Counting proportion of all rows taken by each unique row
Show older comments
Hi Everyone,
Suppose I have a matrix A, and I wish to determine the number of unique rows this matrix has. Then I could form B using:
B = unique(A,'rows')
So far, so good. This yields, say, 5 unique rows out of 100.
My problem is the following. Suppose, having found B, I wish to count for each of the 5 unique rows, how many rows are identical ... and then divided by the total number of rows in A, and sort. This will in this case give a 5 x 1 matrix summing to 100%.
How might this be done?
Regards,
Ulrik.
Accepted Answer
More Answers (1)
Andrei Bobrov
on 20 Jul 2011
more variant
[B, I, J] = unique(X, 'rows');
out = diff(find([1; diff(sort(J)); 1]))/length(J)
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!