This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Class: gmdistribution

Mahalanobis distance to component means


D = mahal(obj,X)


D = mahal(obj,X) computes the Mahalanobis distance (in squared units) of each observation in X to the mean of each of the k components of the Gaussian mixture distribution defined by obj. obj is an object created by gmdistribution or fitgmdist. X is an n-by-d matrix, where n is the number of observations and d is the dimension of the data. D is n-by-k, with D(I,J) the distance of observation I from the mean of component J.


expand all

Generate data from a mixture of two bivariate Gaussian distributions using the mvnrnd function.

MU1 = [1 2];
SIGMA1 = [2 0; 0 .5];
MU2 = [-3 -5];
SIGMA2 = [1 0; 0 1];
rng(1); % For reproducibility
X = [mvnrnd(MU1,SIGMA1,1000);mvnrnd(MU2,SIGMA2,1000)];

hold on

Fit a two-component Gaussian mixture model.

obj = fitgmdist(X,2);
h = ezcontour(@(x,y)pdf(obj,[x y]),[-8 6],[-8 6]);

Compute the Mahalanobis distance of each point in X to the mean of each component of obj.

D = mahal(obj,X);

hb = colorbar;
ylabel(hb,'Mahalanobis Distance to Component 1')

Was this topic helpful?