Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: intersection for long list of cells

Subject: intersection for long list of cells

From: Chris

Date: 16 Apr, 2008 05:28:01

Message: 1 of 7

Hi all, I have two long lists of strings in cells (each
25K entries long) and I'd like to find the indices of
entries that are common between both lists.

I'm hoping to find a faster way of doing this than an
individual search (which takes way to long given the size
of the lists)

Thanks!

Subject: intersection for long list of cells

From: Jos

Date: 16 Apr, 2008 06:22:03

Message: 2 of 7

"Chris " <cag44@removethispitt.edu> wrote in message <fu42p1
$o5k$1@fred.mathworks.com>...
> Hi all, I have two long lists of strings in cells (each
> 25K entries long) and I'd like to find the indices of
> entries that are common between both lists.
>
> I'm hoping to find a faster way of doing this than an
> individual search (which takes way to long given the size
> of the lists)
>
> Thanks!

help intersect

Jos

Subject: intersection for long list of cells

From: Chris

Date: 16 Apr, 2008 12:46:01

Message: 3 of 7

Hi Jos,

Intersect doesn't operate on cells.


"Jos " <DELjos@jasenDEL.nl> wrote in message
<fu45ub$97b$1@fred.mathworks.com>...
> "Chris " <cag44@removethispitt.edu> wrote in message
<fu42p1
> $o5k$1@fred.mathworks.com>...
> > Hi all, I have two long lists of strings in cells
(each
> > 25K entries long) and I'd like to find the indices of
> > entries that are common between both lists.
> >
> > I'm hoping to find a faster way of doing this than an
> > individual search (which takes way to long given the
size
> > of the lists)
> >
> > Thanks!
>
> help intersect
>
> Jos

Subject: intersection for long list of cells

From: Jos

Date: 16 Apr, 2008 12:56:02

Message: 4 of 7

"Chris " <cag44@removethispitt.edu> wrote in message
<fu4se9$oh9$1@fred.mathworks.com>...

> "Jos " <DELjos@jasenDEL.nl> wrote in message
> <fu45ub$97b$1@fred.mathworks.com>...
> > "Chris " <cag44@removethispitt.edu> wrote in message
> <fu42p1
> > $o5k$1@fred.mathworks.com>...
> > > Hi all, I have two long lists of strings in cells
> (each
> > > 25K entries long) and I'd like to find the indices of
> > > entries that are common between both lists.
> > >
> > > I'm hoping to find a faster way of doing this than an
> > > individual search (which takes way to long given the
> size
> > > of the lists)
> > >
> > > Thanks!
> >
> > help intersect
> >
> > Jos
>
> Hi Jos,
>
> Intersect doesn't operate on cells.
>
>

(fixed top-posting)

Apparently you mean something else then "I have two long
lists of strings in cells (each 25K entries long) and I'd
like to find the indices of entries that are common between
both lists.", since:

A = {'a','b','c'} ;
B = {'a','b','d'} ;
intersect(A,B)
ans =

    'a' 'b'

Can you give a small(!!) example of the inputs and the
desired output?

Jos

Subject: intersection for long list of cells

From: nor ki

Date: 16 Apr, 2008 13:02:01

Message: 5 of 7

the help says:

INTERSECT(A,B)
A and B can be cell arrays of strings.
and this one works on my machine:

for n = 1:20
    t{n} = num2str(n+10);
    tt{n} = num2str(n+10);
end
intersect(t,tt)



"Chris " <cag44@removethispitt.edu> wrote in message
<fu4se9$oh9$1@fred.mathworks.com>...
> Hi Jos,
>
> Intersect doesn't operate on cells.
>
>
> "Jos " <DELjos@jasenDEL.nl> wrote in message
> <fu45ub$97b$1@fred.mathworks.com>...
> > "Chris " <cag44@removethispitt.edu> wrote in message
> <fu42p1
> > $o5k$1@fred.mathworks.com>...
> > > Hi all, I have two long lists of strings in cells
> (each
> > > 25K entries long) and I'd like to find the indices of
> > > entries that are common between both lists.
> > >
> > > I'm hoping to find a faster way of doing this than an
> > > individual search (which takes way to long given the
> size
> > > of the lists)
> > >
> > > Thanks!
> >
> > help intersect
> >
> > Jos
>

Subject: intersection for long list of cells

From: Chris

Date: 16 Apr, 2008 13:05:09

Message: 6 of 7

Hello Jos,

This is weird, tried it again after rebooting and it
worked. Checked the exact same set of commands was giving
me an error before. Thanks for the help

"Jos " <DELjos@jasenDEL.nl> wrote in message <fu4t12
$d8u$1@fred.mathworks.com>...
> "Chris " <cag44@removethispitt.edu> wrote in message
> <fu4se9$oh9$1@fred.mathworks.com>...
>
> > "Jos " <DELjos@jasenDEL.nl> wrote in message
> > <fu45ub$97b$1@fred.mathworks.com>...
> > > "Chris " <cag44@removethispitt.edu> wrote in message
> > <fu42p1
> > > $o5k$1@fred.mathworks.com>...
> > > > Hi all, I have two long lists of strings in cells
> > (each
> > > > 25K entries long) and I'd like to find the indices
of
> > > > entries that are common between both lists.
> > > >
> > > > I'm hoping to find a faster way of doing this than
an
> > > > individual search (which takes way to long given
the
> > size
> > > > of the lists)
> > > >
> > > > Thanks!
> > >
> > > help intersect
> > >
> > > Jos
> >
> > Hi Jos,
> >
> > Intersect doesn't operate on cells.
> >
> >
>
> (fixed top-posting)
>
> Apparently you mean something else then "I have two long
> lists of strings in cells (each 25K entries long) and I'd
> like to find the indices of entries that are common
between
> both lists.", since:
>
> A = {'a','b','c'} ;
> B = {'a','b','d'} ;
> intersect(A,B)
> ans =
>
> 'a' 'b'
>
> Can you give a small(!!) example of the inputs and the
> desired output?
>
> Jos

Subject: intersection for long list of cells

From: Kris De Gussem

Date: 16 Apr, 2008 14:12:13

Message: 7 of 7

Chris schreef:
> Hi all, I have two long lists of strings in cells (each
> 25K entries long) and I'd like to find the indices of
> entries that are common between both lists.
>
> I'm hoping to find a faster way of doing this than an
> individual search (which takes way to long given the size
> of the lists)
>
> Thanks!

Maybe you can have a look at the binary tree object named BTree in the GSTools
toolbox. You can find it on the matlab file exchange server:

http://tinyurl.com/2f8cll

You can use something like
tree1=BTree(list1);
tree2=BTree(list2);
tmp = intersect(unique(list1), unique(list2))
for i=1:length(tmp)
res1=getitem(tree1, tmp{i});
res2=getitem(tree2, tmp{i});
positions{i,1} = cat(1,res1.itemvalues{:});
positions{i,2} = cat(1,res2.itemvalues{:});
end


The result is found in positions and this solution should work with stringlists,
numeric vectors and 1D cell arrays with both numbers and strings.

Regards
Kris

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
intersect search find strings cellstr Chris 16 Apr, 2008 01:30:20
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics