function d = mahal_symetric(X1, X2, E1, E2) % function d = mahal_symetric(X1, X2, E1, E2) % Symetric Mahalanobis distance % % mahal_symetric(X1, X2) : where X1 and X2 are the data of the first and % second group of data to be compared, in the columns % % mahal_symetric(u1, u2, E1, E2) : where u1 and u2 are the centroids of the % two groups of data; and E1 and E2 are the covariance matrix of each % group of data % % Work protected by the Attribution-NonCommercial-ShareAlike 3.0 Unported % Creative Commons license % http://creativecommons.org/licenses/by-nc-sa/3.0/ if nargin==2, u1 = mean(X1)'; %mean of each collumn E1 = cov(X1); %each collumn is a variable u2 = mean(X2)'; %mean of each collumn E2 = cov(X2); %each collumn is a variable elseif nargin==4, u1 = X1; u2 = X2; else display('Wrong number of input arguments, please use mahal_symetric(X1, X2) or mahal_symetric( u1, u2, E1, E2)'), return, end d = ((u1-u2)'*pinv(E2)*(u1-u2) + (u2-u1)'*pinv(E1)*(u2-u1))/2;