Searching for rows of cell arrays containing strings in a different cell array having a collection of multiple other strings

2 views (last 30 days)
I have to search exact same rows between two cell arrays, but my my rows aren't exactly similar among those two. For example;
A = {'ABCS' '100'; 'A' '10'; 'C' '0'; 'ASD' '12'};
B = {'ABCS' '100'; 'A' '100'; 'C' '0'};
I have to search all the rows of B in A.
I am able to do a row by row search but its difficult to do when the size of the cell arrays are
A : 19 million rows
B : 29,000 rows
I have gone through most of the posts but couldn't get hold of it.
Thanks
  4 Comments
BR
BR on 3 Jun 2019
Yes I used ismember () as follows;
[~,index]=ismember(A(:),B(:));
ind=find(index(:,1)==index(:,2));
But this obviously didn't work as this will return index values considering both columns as one (I guess).
Then I implemented the index by index search for B(:,1) in A (:,1) and for matched indices look for the second column value.

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 3 Jun 2019
This is not a very beautiful solution, nor might it be suitable for such large cell arrays:
>> A = {'ABCS' '100'; 'A' '10'; 'C' '0'; 'ASD' '12'};
>> B = {'ABCS' '100'; 'A' '100'; 'C' '0'};
>> [X,Y] = ismember([char(B(:,1)),char(B(:,2))],[char(A(:,1)),char(A(:,2))],'rows')
X =
1
0
1
Y =
1
0
3
  5 Comments
BR
BR on 4 Jun 2019
Edited: BR on 4 Jun 2019
That is really amazing. That works much efficiently. Bit slow again for huge datasets but yeah works really well.
Big help, man.
Thanks a lot.
Cheers

Sign in to comment.

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by