euclidean.m

来自「Diversos ejemplos sobre la aplicacion de」· M 代码 · 共 26 行

M
26
字号
function dist = euclidean(x,y)
% function dist = euclidean(x,y)
% 
% Calculates the Euclidean distance between two vectors x and y
%                            A. Student, ICS 175A 
%  Inputs:
%    x, y:  2 vectors of real numbers, each of size 1 x n
%  Outputs:
%    dist: the Euclidean distance between x and y
[xr, xc] = size(x);
[yr, yc] = size(y);

if (xc ~= yc)
   error('input vectors must be the same length');
end

if (xr ~= 1  | yr ~= 1)
   error('inputs must both be row vectors (1 row, n columns)');
end

% calculate a vector of component_by_component distances
delta = x - y;

% now calculate the Euclidean distance
dist = norm(delta); %sqrt(delta.*delta);

⌨️ 快捷键说明

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