1 function [d] = mahal(X,Y)
2 % MAHAL return the Mahalanobis' D-square distance between the
3 % multivariate samples x and y, which must have the same number
4 % of components (columns), but may have a different number of observations (rows).
8 % d(k) = (X(k,:)-MU)*inv(SIGMA)*(X(k,:)-MU)'
10 % where MU and SIGMA are the mean and the covariance matrix of Y
13 % see also: TRAIN_SC, TEST_SC, COVM
17 % $Id: train_sc.m 2140 2009-07-02 12:03:55Z schloegl $
18 % Copyright (C) 2009 by Alois Schloegl <alois.schloegl@gmail.com>
19 % This function is part of the NaN-toolbox
20 % http://pub.ist.ac.at/~schloegl/matlab/NaN/
22 % This program is free software; you can redistribute it and/or
23 % modify it under the terms of the GNU General Public License
24 % as published by the Free Software Foundation; either version 2
25 % of the License, or (at your option) any later version.
27 % This program is distributed in the hope that it will be useful,
28 % but WITHOUT ANY WARRANTY; without even the implied warranty of
29 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 % GNU General Public License for more details.
32 % You should have received a copy of the GNU General Public License
33 % along with this program; if not, write to the Free Software
34 % Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
40 error('number of columns of X and Y do not fit');
43 IR = inv(covm(Y,'E'));
46 D = [ones(size(X,1),1),X];