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

cell arraysfindstring

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

Best Answer

  • 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