필터 지우기
필터 지우기

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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by