how to find unique rows in cell array in matlab

149 次查看(过去 30 天)
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'

采纳的回答

Matt J
Matt J 2012-11-4
unique(cell2mat(levelx),'rows')
  2 个评论
Jwana
Jwana 2012-11-4
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 2012-11-4
编辑:Matt J 2012-11-4
[~,idx]=unique(cell2mat(levelx),'rows');
unique_levelx = levelx(idx,:);

请先登录,再进行评论。

更多回答(2 个)

Jim Hokanson
Jim Hokanson 2013-5-1
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)))

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by