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

📄 distmatrix.m

📁 K-means algoritnm implemented with java
💻 M
字号:
function d=DistMatrix(A,B)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DISTMATRIX return distance matrix between point A=[x1 y1] and B=[x2 y2]
% Author: Kardi Teknomo, Ph.D.
% see http://people.revoledu.com/kardi/
%
% Number of point in A and B are not necessarily the same.
% It can be use for distance-in-a-slice (Spacing) or distance-between-slice (Headway),
%
% A and B must contain two column,
% first column is the X coordinates
% second column is the Y coordinates
% The distance matrix are distance between points in A as row
% and points in B as column.
% example: Spacing= dist(A,A)
%          Headway = dist(A,B), with hA ~= hB or hA=hB
%          A=[1 2; 3 4; 5 6]; B=[4 5; 6 2; 1 5; 5 8]
%          dist(A,B)= [ 4.24   5.00   3.00  7.21;
%                       1.41   3.61   2.24  4.47;
%                       1.41   4.12   4.12  2.00 ]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[hA,wA]=size(A);
[hB,wB]=size(B);
if hA==1& hB==1 
   d=sqrt(dot((A-B),(A-B)));
else
   C=[ones(1,hB);zeros(1,hB)];
   D=flipud(C);
   E=[ones(1,hA);zeros(1,hA)];
   F=flipud(E);
   G=A*C;
   H=A*D;
   I=B*E;
   J=B*F;
   d=sqrt((G-I').^2+(H-J').^2);
end

⌨️ 快捷键说明

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