I’m trying to solve the following problem, and I need to do it as efficiently as possible (i.e. trying to avoid loops as much as I can).
I have two cell arrays, namely A and B. Each cell of A and B contains a string of characters. The length of these strings of characters is variable. Let’s say:
A={‘life is wonderful’, ‘matlab makes your dreams come true’};
B={‘life would be meaningless without wonderful matlab’, ‘what a wonderful world’, ‘the shoemaker makes shoes’, ‘rock and roll baby’};
Moreover, the number of elements of cell array B is around three orders of magnitude larger than that of cell array A.
My goal is to find how many words of every char string in A also appear in every char string of B.
For the previous example, a suitable result could be something like:
match = [2 1 0 0
1 0 1 0]
The first row indicates how many words in the 1st char string of A appear in the four char strings of B. And the second row, the same for the 2nd char string of A.
The double loop implementation is straightforward, but very time consuming especially because of the length of cell array B (over 3 million cells).
Any ideas? Thank you very much.
Xavier