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

📄 dist_sqr_.m

📁 This a collection of MATLAB functions for extended Kalman filtering, unscented Kalman filtering, par
💻 M
字号:
function d2 = dist_sqr_(s, x)
%function d2 = dist_sqr_(s, x)
%
% INPUTS:
%   s - matrix of N column vectors
%   x - a single column vector OR 
%       a matrix of N column vectors
%
% OUTPUT:
%   d2 - an array of N square distances
%
% Compute the square distances from x to each vector in s. If x is a matrix of N column
% vectors, compute the square distance of x(:,i) to s(:,i) for each i. To compute the set 
% of Euclidean distances, simply write: d = sqrt(d2).
%
% Tim Bailey 2005.

[Ds,Ns] = size(s);
[Dx,Nx] = size(x);

if Ds ~= Dx, error('Vectors must have the same dimension'), end

switch Nx
case 1
    xdif = x(:, ones(1,Ns)) - s; 
case Ns
    xdif = x - s; 
otherwise 
    error('Second parameter must either have as many columns as the first parameter or be a single column vector.'), 
end

d2 = sum(xdif.*xdif, 1);

⌨️ 快捷键说明

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