distance.m

来自「计量工具箱」· M 代码 · 共 20 行

M
20 行
字号
function D = distance(xc,yc)
% PURPOSE: Computes the list of pairwise distances for a given set of locations (loc).
% ----------------------------------------------------------
% Usage: D = distance(xc,yc)
% where: xc,yc are vectors of latt-long coordinates for each location
% ----------------------------------------------------------
% Returns: D = (n x n)-matrix of pairwise distances

% Written by: TONY E. SMITH, 2/10/98

n = length(xc) ;  %number of locations
% Start procedure.
X = xc ; %column vector
Y = yc ; %column vector
U = ones(n,1) ; %column vector
XX = X*U' - U*X' ;
YY = Y*U' - U*Y' ;
D = (XX.^2 + YY.^2) ;

⌨️ 快捷键说明

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