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

New to MATLAB?

how to find unique rows in cell array in matlab

Asked by Jwana

Jwana (view profile)

on 4 Nov 2012
Accepted Answer by Matt J

Matt J (view profile)

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

Jwana (view profile)

Products

No products are associated with this question.

2 Answers

Answer by Matt J

Matt J (view profile)

on 4 Nov 2012
Accepted answer
unique(cell2mat(levelx),'rows')

2 Comments

Jwana

Jwana (view profile)

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

Matt J (view profile)

on 4 Nov 2012
[~,idx]=unique(cell2mat(levelx),'rows');
unique_levelx =  levelx(idx,:);
Matt J

Matt J (view profile)

Answer by Jim Hokanson

Jim Hokanson (view profile)

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

Jim Hokanson (view profile)

Contact us