📄 euclidean.m
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -