# 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)
BR on 3 Jun 2019
Edited: BR on 4 Jun 2019
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
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.

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
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