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

Thread Subject:
unique rows in cell array

Subject: unique rows in cell array

From: Wendy

Date: 28 Sep, 2010 01:24:05

Message: 1 of 4

Hi all,

I am a 2000 by 3 cell, e.g.

{
'MONO1.2' 'HSC1.3' 'CSF1'
'PRE_BCELL2.3' 'HSC1.3' 'PDGFA'
'PRE_BCELL2.3' 'HSC1.3' 'PDGFA'
'GMP.GRAN1.2.3' 'HSC1.3' 'CSF1'
'BCELLA1.2.3.4' 'HSC1.3' 'DTL'
}

I want to return a cell array with unique rows, e.g.
{
'MONO1.2' 'HSC1.3' 'CSF1'
'PRE_BCELL2.3' 'HSC1.3' 'PDGFA'
'GMP.GRAN1.2.3' 'HSC1.3' 'CSF1'
'BCELLA1.2.3.4' 'HSC1.3' 'DTL'
}

Is there any function in matlab for that? I used unique(X,'rows'), but it gives me an error of "Input must be a cell array of strings".

Thank you very much,
Wendy

Subject: unique rows in cell array

From: Bruno Luong

Date: 28 Sep, 2010 06:22:05

Message: 2 of 4

c={
'MONO1.2' 'HSC1.3' 'CSF1'
'PRE_BCELL2.3' 'HSC1.3' 'PDGFA'
'PRE_BCELL2.3' 'HSC1.3' 'PDGFA'
'GMP.GRAN1.2.3' 'HSC1.3' 'CSF1'
'BCELLA1.2.3.4' 'HSC1.3' 'DTL'
}

u = sortrows(c);
[u{end+1,:}] = deal('');
j = ~all(cellfun(@strcmp, u(1:end-1,:), u(2:end,:)),2);
u=u(j,:)

% Bruno

Subject: unique rows in cell array

From: Bruno Luong

Date: 28 Sep, 2010 06:30:40

Message: 3 of 4

Actually STRCMP works directly on CELL:

u = sortrows(c);
[u{end+1,:}] = deal('');
j = ~all(strcmp(u(1:end-1,:), u(2:end,:)),2);
u=u(j,:)

% Bruno

Subject: unique rows in cell array

From: Mojgan

Date: 2 May, 2013 02:49:10

Message: 4 of 4

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <i7s22f$prp$1@fred.mathworks.com>...
> Actually STRCMP works directly on CELL:
>
> u = sortrows(c);
> [u{end+1,:}] = deal('');
> j = ~all(strcmp(u(1:end-1,:), u(2:end,:)),2);
> u=u(j,:)
>
> % Bruno

Hi

What if cell array contains both string and numeric values?
Strcmp dosen't work in such situations

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us