I need to find the cosine similarity between two frequency vectors in MATLAB.
Example vectors:
a = [2,3,4,4,6,1] b = [1,3,2,4,6,3]
How
If you have the Statistics toolbox, you can use the pdist2 function with the 'cosine' input flag, which gives 1 minus the cosine similarity:
'cosine'
a = [2,3,4,4,6,1]; b = [1,3,2,4,6,3]; result = 1-pdist2(a, b, 'cosine');