資源簡介
馬氏距離的matlaB實現 源代碼
代碼片段和文件信息
function?d?=?mahalanobis(X?Mu?C)
%MAHALANOBIS?Mahalanobis?distance.
%???D?=?MAHALANOBIS(X?MU?C)?returns?the?Mahalanobis?distance?between
%???the?length?p?vectors?X?and?MU?given?the?p?by?p?covariance?matrix
%???C.?If?omitted?it?is?assumed?that?C?is?the?identity?matrix(單位矩陣/恒等矩陣)
%???EYE(p).?If?either?X?or?MU?is?an?n?by?p?matrix?D?will?be?returned
%???as?an?n?by?g?matrix?where?n?is?the?number?of?rows?in?X?and?g?is
%???the?number?of?rows?in?MU?where?each?entry?i?j?corresponds?to?the
%???mahalanobis?distance?between?row?i?of?X?and?row?j?of?MU.?If?MU?is
%???simply?0?it?is?treated?as?the?origin?from?which?Mahalanobis
%???distance?to?X?is?calculated.?C?must?be?a?positive?definite
%???symmetric?matrix.
%
%???The?Mahalanobis?distance?between?vectors?X(i:)?and?MU(j:)?is
%???defined?as:
%
%???D(ij)?=?((X(i:)?-?MU(j:))‘*INV(C)*(X(i:)?-?MU(j:))).^(1/2)
%???Copyright?(c)?1999?Michael?Kiefte.
%???$Log$
error(nargchk(2?3?nargin))
if?isempty(X)?|?~isa(X?‘double‘)?|?~isreal(X)?|?
評論
共有 條評論