Calculate mahalanobis distance of matrix for each row

9 次查看(过去 30 天)
I want to calculate mahalanobis distance of matrix A for each row with respect to average value of column.
I use 'mahal' function in matlab
A = [110 -100 0; 100 -100 0; 10 0 0; 0 10 0; 0 -10 20; 0 -10 10; 0 0 10;-10 -10 -10; -10 0 0];
mean_row = mean(A,1);
mahal(mean_row,A)
But it gives zero value.
The result should be:
MD = [2.0937; 1.9970; 0.9072; 0.9517; 2.2387; 1.3394; 1.0792; 2.2596;0.9072]

采纳的回答

Chunru
Chunru 2021-11-29
编辑:Chunru 2021-11-29
A = [110 -100 0; 100 -100 0; 10 0 0; 0 10 0; 0 -10 20; 0 -10 10; 0 0 10;-10 -10 -10; -10 0 0];
mean_row = mean(A,1);
whos
Name Size Bytes Class Attributes A 9x3 216 double mean_row 1x3 24 double
d = pdist2(A, mean_row, 'mahalanobis')
d = 9×1
1.8757 1.7646 1.5110 1.6756 2.0319 1.0264 0.9549 2.2982 0.9496
  1 个评论
NA
NA 2021-11-30
编辑:NA 2021-11-30
I checked out other data set and found that the result is different from the code.
I have this data set:
A = [10 -10; 1 0; -1 0; 0 -1; 0 1 ;11 -10; -1 -1]
The Mahalanobis distance that I got from your code is
1.4725
1.2957
0.83996
0.74575
1.4513
1.5646
1.5287
but the actual result is
I do not understand why I could get same result.
I mean, same thing happens for this data set
A = [110 -100 0; 100 -100 0; 10 0 0; 0 10 0; 0 -10 20; 0 -10 10; 0 0 10;-10 -10 -10; -10 0 0];
the result should be
But I got different result.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by