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)
"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!
"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
"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?
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
>
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
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:
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.
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.