How to calculate cosine similarity between two frequency vectors in MATLAB?

前端 未结 2 1906
小蘑菇
小蘑菇 2021-01-28 04:19

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

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-28 05:10

    If you have the Statistics toolbox, you can use the pdist2 function with the 'cosine' input flag, which gives 1 minus the cosine similarity:

    a = [2,3,4,4,6,1];
    b = [1,3,2,4,6,3];
    result = 1-pdist2(a, b, 'cosine');
    

提交回复
热议问题