title: MATLAB: words matching between cell arrays of strings
body: <p>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).</p>
  
  <p>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:</p>
  
  <pre><code>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’};
  </code></pre>
  
  <p>Moreover, the number of elements of cell array B is around three orders of magnitude larger than that of cell array A.</p>
  
  <p>My goal is to find how many words of every char string in A also appear in every char string of B.</p>
  
  <p>For the previous example, a suitable result could be something like:</p>
  
  <pre><code>match = [2 1 0 0
  1 0 1 0]
  </code></pre>
  
  <p>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.</p>
  
  <p>The double loop implementation is straightforward, but very time consuming especially because of the length of cell array B (over 3 million cells).</p>
  
  <p>Any ideas? Thank you very much.</p>
  
  <p>Xavier</p>