Thread Subject: Unique rows with a twist

Subject: Unique rows with a twist

From: ra ti

Date: 22 Oct, 2008 19:42:02

Message: 1 of 2

hi,

I need some help with solving this problem.

Suppose we have
 A cell matrix of strings with 2 columns( Actually it is very big):

A = { 'XYZ' '1'
                'X' '1'}

What is the best way to get UNiQUE rows with ONLY the FIRST OCCURENCE that is of maximum length of the two. I.e, I want the function to return

B = 'XYZ' '1'

because 1 occurs twice and XYZ is the largest of those two.

Currently unique(A,'rows') gives both the rows.

Subject: Unique rows with a twist

From: Thomas Clark

Date: 29 Oct, 2008 12:20:03

Message: 2 of 2

Can I just clarify the problem?

It seems you're looking to remove rows which (in, say, column 1) contain some of the same letters. Or is it the first letter? Or is it the one with maximum length in the first column, given that the second column matches? Or a whole number of other possibilities...

To help us understand what you need, what would be the outcome of your ideal function if it was given the following arrays:

A = {'XYZ' '1'
      'X' '1'
      'Y' '1'}

B = {'XYZ' '1'
      'XYZQ' '1'}

C = {'XYZQ' '1'}
      'XYZ' '1'}

D = {'XYZQ' '1'
      'Q' '1'}

E = {'R' '1'
      'R' '2'
      'RS' '2'}

F = {'ABCD' '1'
      'PQRSWEA' '1'
      'APQRSWE' '1'
      'AB' '1'}

G = {'ABCD' '1'
      'PQRSWEA' '1'
      'APQRSWE' '1'
      'ABQWERTYUIOP' '1'}


??

That might help us figure out what you're looking for a bit better.

As an initial hint, I've a feeling you'd be looking to use some combination of unique with logical statement(s).

Kind Regards

Tom Clark

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
unique rows ra ti 22 Oct, 2008 15:45:04
rssFeed for this Thread

Contact us at files@mathworks.com