Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

how to find unique rows in cell array in matlab

Asked by Jwana on 4 Nov 2012

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'

0 Comments

Jwana

Products

No products are associated with this question.

2 Answers

Answer by Matt J on 4 Nov 2012
Accepted answer
unique(cell2mat(levelx),'rows')

2 Comments

Jwana on 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 on 4 Nov 2012
[~,idx]=unique(cell2mat(levelx),'rows');
unique_levelx =  levelx(idx,:);
Matt J
Answer by Jim Hokanson on 1 May 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

0 Comments

Jim Hokanson

Contact us