⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cossimilarity.m

📁 一个关于数据聚类和模式识别的程序,在生物化学,化学中因该都可以用到.希望对大家有用,谢谢支持
💻 M
字号:
function cosine = cosSimilarity(mat1, mat2)
% cosSimilarity: Cosine of the angles betweeen two set of vectors
%	Usage: cosine = cosSimilarity(mat1, mat2)
%	Returns the cosine of the angles between two set of vectors mat1 and mat2.
%	The element at row i and column j of the return matrix is the cosine of the angle between
%	column i of mat1 and column j of mat2.

%	Roger Jang, 19971227, 20080915.

if nargin<1, selfdemo; return; end
if nargin<2, mat2=mat1; end

leng1 = (sum((mat1).^2).^.5);
leng2 = (sum((mat2).^2).^.5);
cosine = (mat1.'*mat2)./(leng1.'*leng2);

% ====== Selfdemo
function selfdemo
mat1=rand(3);
mat2=rand(3);
cos=feval(mfilename, mat1, mat2)

⌨️ 快捷键说明

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