Counting number of unique elements in a matrix

1 visualización (últimos 30 días)
Matlab2010
Matlab2010 el 10 de En. de 2013
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!!
  2 comentarios
Matlab2010
Matlab2010 el 10 de En. de 2013
Editada: Matlab2010 el 10 de En. de 2013
SOLVED:
myData = randi([0 20], [10000 2]); %make up some data
[C,ia,ic] = unique(myData,'rows');
[nOccurances IX] = sort(histc(ic, 1:length(ic)), 'descend');
idY = (nOccurances==0);
nOccurances(idY) = [];
IX(idY) = [];
myDataSorted = [nOccurances C(IX,:)];
Matt J
Matt J el 10 de En. de 2013
Then you should either delete the question or submit then Accept your own solution as an Answer

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by