📄 mahalan.m
字号:
function dist = mahalan(X,mi,sigma)
% MAHALAN Mahalanobis distance.
% dist=mahalan(X,mi,sigma)
%
% MAHALAN calculates Mahalanobis distance for given vectors
% in the matrix X, where mi is the vector from which the distance
% is calculated and sigma is the covariance matrix (bending of
% the feature space).
%
% Input:
% X [NxK] matrix of K vectors for which the distance is computed,
% where N is the dimension of the feature space.
% mi [Nx1] mean vlaue.
% sigma [NxN] covariance matrix.
%
% Output:
% dist [1xK] vector of distances for given vectors in the matrix X.
%
% Statistical Pattern Recognition Toolbox, Vojtech Franc, Vaclav Hlavac
% (c) Czech Technical University Prague, http://cmp.felk.cvut.cz
% Written Vojtech Franc (diploma thesis) 19.3.2000
% Modifications
% 27-Oct-2001, V.Franc
% 25. 6.00 V. Hlavac, comments into English.
% gets # of points
K=size(X,2);
% gets dim
DIM=size(X,1);
% makes mi a column vector
mi=mi(:);
% computes it for all the points in matrix X
if DIM == 1,
dist=((X-repmat(mi,1,K))'*inv(sigma).*(X-repmat(mi,1,K))')';
else
dist=sum( ((X-repmat(mi,1,K))'*inv(sigma).*(X-repmat(mi,1,K))')');
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -