Counting number of unique elements in a matrix
7 views (last 30 days)
I have a matrix, 2xT. It contains value PAIRS that are unique and some that are repeated.
I would like to order the matrix by the pairs that occur the most frequently.
myData = randi([0 20], [10000 2]); %make up some data
[C,ia,ic] = unique(myData,'rows');
such that %isequal(C(ic,:), myData) =1. Great.
I now try and work out the ordering
[nOccurances IX] = sort(histc(ic, 1:length(ic)), 'descend');
This gives nOccurances which looks sensible.
Now I try and output:
myDataSorted = myData(ic(IX),:);
The output value is just wrong.
Where have I gone wrong? Thank you!!