cosfn.m

来自「独立主成分分析的工具箱」· M 代码 · 共 13 行

M
13
字号
% function [S] = cosFn(mat1,mat2),
% Computes the cosine (normalized dot product) between training vectors in 
% columns of mat1 and test vectors in columns of mat2. Outputs a matrix of 
% cosines (similarity matrix). 

function [S] = cosFn(mat1,mat2),
  
  denom = sum(mat1.^2,1)*sum(mat2'.^2,2);
  denom (find(denom==0)) = 0.00000000000000000000001;
  numer = mat1'*mat2;
  
  S = numer./denom;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?