title: How to compute cosine similarity using two matrices
body: <p>I have two matrices, A (dimensions M x N) and B (N x P). In fact, they are collections of vectors - row vectors in A, column vectors in B. I want to get cosine similarity scores for every pair <code>a</code> and <code>b</code>, where <code>a</code> is a vector (row) from matrix A and <code>b</code> is a vector (column) from matrix B.</p>
  
  <p>I have started by multiplying the matrices, which results in matrix <code>C</code> (dimensions M x P). </p>
  
  <blockquote>
    <p>C = A*B</p>
  </blockquote>
  
  <p>However, to obtain cosine similarity scores, I need to divide each value <code>C(i,j)</code> by the norm of the two corresponding vectors. Could you suggest the easiest way to do this in Matlab?</p>