mahalanobis distance for 2 vectors matlab

6 次查看(过去 30 天)
Hey,
I tried the method mahal to calculate the mahalanobis distance between 2 vectors of 27 variables(columns) e.g. mahal(X,Y) where X and Y are the 2 vectors but it comes up with an error. After a few minutes of research I got that I can't use it like this but I'm still not sure sure why? can some explain to me why?
Also I have below an example of mahal method :
mahal([1.55 5 32],[5.76 43 34; 6.7 32 5; 3 3 5; 34 12 6;])
ans =
11.1706
can someone clarify how matlab calculated the answer in this case?

采纳的回答

Roger Stafford
Roger Stafford 2013-5-11
There appears to be a misconception here. Mahalanobis distance has no meaning between two multiple-element vectors. Ideally it is a distance between a vector (or distances between a set of vectors) and some given distribution defined by means and covariances. See the Wikipedia website
http://en.wikipedia.org/wiki/Mahalanobis_distance
In Mathworks' 'mahal' function
d = mahal(Y,X) ,
that distribution is approximated from the X array, which must have more rows than columns to be meaningful. In your case you were trying to use only one row in the second argument and that would not give a meaningful distribution. I suggest you carefully read the documentation at:
http://www.mathworks.com/help/stats/mahal.html
  3 个评论
babi psylon
babi psylon 2013-11-12
hi Roger
Can you elaborate on the difference between mahal() en pdist2()? My full question is listed here: http://www.mathworks.com/matlabcentral/answers/105829-mahalanobis-distance- in-matlab-pdist2-vs-mahal-function
Babi
AlessioX
AlessioX 2018-5-28
Not entirely correct. At the end of the proposed code, one should add
d = sqrt(d);
for the result to be correct.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by