フィルターのクリア

Calculate mahalanobis distance of matrix for each row

17 ビュー (過去 30 日間)
NA
NA 2021 年 11 月 29 日
編集済み: NA 2021 年 11 月 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 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by