how to find unique rows in cell array in matlab

28 visualizzazioni (ultimi 30 giorni)
hi.. how to find the unique rows for the following cell array:
levelx=
'GO:0016787' 'GO:0006412' 'GO:0030533'
'GO:0008150' 'GO:0006412' 'GO:0030533'
'GO:0006810' 'GO:0006412' 'GO:0030533'
'GO:0016787' 'GO:0006412' 'GO:0030533'
'GO:0008150' 'GO:0006412' 'GO:0030533'
'GO:0006810' 'GO:0006412' 'GO:0030533'
'GO:0016787' 'GO:0006412' 'GO:0030533'
'GO:0008150' 'GO:0006412' 'GO:0030533'
'GO:0006810' 'GO:0006412' 'GO:0030533'
'GO:0016787' 'GO:0006412' 'GO:0030533'
'GO:0008150' 'GO:0006412' 'GO:0030533'
'GO:0006810' 'GO:0006412' 'GO:0030533'
'GO:0016787' 'GO:0006412' 'GO:0030533'
'GO:0008150' 'GO:0006412' 'GO:0030533'
'GO:0006810' 'GO:0006412' 'GO:0030533'
'GO:0016787' 'GO:0006412' 'GO:0030533'
'GO:0008150' 'GO:0006412' 'GO:0030533'
'GO:0006810' 'GO:0006412' 'GO:0030533'
'GO:0016787' 'GO:0006412' 'GO:0030533'
'GO:0008150' 'GO:0006412' 'GO:0030533'
'GO:0006810' 'GO:0006412' 'GO:0030533'
'GO:0016787' 'GO:0006412' 'GO:0030533'
'GO:0008150' 'GO:0006412' 'GO:0030533'
'GO:0006810' 'GO:0006412' 'GO:0030533'
'GO:0016787' 'GO:0006412' 'GO:0030533'
'GO:0008150' 'GO:0006412' 'GO:0030533'
'GO:0006810' 'GO:0006412' 'GO:0030533'
'GO:0016787' 'GO:0006412' 'GO:0030533'
'GO:0008150' 'GO:0006412' 'GO:0030533'
'GO:0006810' 'GO:0006412' 'GO:0030533'

Risposta accettata

Matt J
Matt J il 4 Nov 2012
unique(cell2mat(levelx),'rows')
  2 Commenti
Jwana
Jwana il 4 Nov 2012
thank you for your response .. but how can I return them again to cell ?? because it shows like this:
GO:0006810GO:0005215GO:0030533 GO:0006810GO:0006412GO:0030533 GO:0008150GO:0005215GO:0030533 GO:0008150GO:0006412GO:0030533 GO:0008150GO:0006810GO:0003774 GO:0008150GO:0006810GO:0005215 GO:0008150GO:0006810GO:0006412 GO:0008150GO:0006810GO:0030533 GO:0008150GO:0016787GO:0005215 GO:0008150GO:0016787GO:0006412 GO:0016787GO:0005215GO:0030533 GO:0016787GO:0006412GO:0030533
Matt J
Matt J il 4 Nov 2012
Modificato: Matt J il 4 Nov 2012
[~,idx]=unique(cell2mat(levelx),'rows');
unique_levelx = levelx(idx,:);

Accedi per commentare.

Più risposte (2)

Jim Hokanson
Jim Hokanson il 1 Mag 2013
The solution above works since the contents concatenate into a hyperrectangle. Put more plainly, in this case, the solution works since all the entries are the same size.
A more general solution can be found at my FEX submission: 25917: Unique Rows for a Cell Array

Andreas Thealnder Bertelsen
For unstructured data use table.
pairs{1,1} = '02-Target-180814_1800.wav';
pairs{1,2} = 1525;
pairs{2,1} = '02-Target-180814_1800.wav';
pairs{2,2} = 1563;
pairs{3,1} = '02-Target-180814_1800.wav';
pairs{3,2} = 1525;
table2cell(unique(cell2table(pairs)))

Community Treasure Hunt

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

Start Hunting!

Translated by