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 a
and b
, where a
is a vector (row) from matrix A and b
is a vector (column) from matrix B.
I have started by multiplying the matrices, which results in matrix C
(dimensions M x P).
C = A*B
However, to obtain cosine similarity scores, I need to divide each value C(i,j)
by the norm of the two corresponding vectors. Could you suggest the easiest way to do this in Matlab?