MATLAB求马氏距离(Mahalanobis distance)
1.马氏距离计算公式
d2(xi,xj)=(xi-xj)TS-1(xi-xj)
其中,S是总体的协方差矩阵,而不是样本的协方差矩阵。
2.matlab中现有的函数
>> x=[155 66;180 71;190 73;160 60;190 68;150 58;170 75]
x =
155 66
180 71
190 73
160 60
190 68
150 58
170 75
>> Y = pdist(x,'mahal')
Y =
Columns 1 through 5
1.572816369474562 2.201942917264386 1.635800793960578 2.695107559788053 1.478413355546874
Columns 6 through 10
1.404831102709996 0.629126547789825 1.713111078598705 1.391260434780810 2.103238561272744
Columns 11 through 15
1.590313263839551 2.103238561272744 1.090736759616727 2.589223001191582 2.033867095735081
Columns 16 through 20
1.825496244926879 0.629126547789825 2.743712945526665 2.441925172889290 2.980237487501595