Calculate mahalanobis distance of matrix for each row

8 visualizaciones (últimos 30 días)
NA
NA el 29 de Nov. de 2021
Editada: NA el 30 de Nov. de 2021
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]

Respuesta aceptada

Chunru
Chunru el 29 de Nov. de 2021
Editada: Chunru el 29 de Nov. de 2021
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 comentario
NA
NA el 30 de Nov. de 2021
Editada: NA el 30 de Nov. de 2021
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.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by