function d = mahanoboulis(xs, mean, cov) 
% calculates the mahanoboulis distance of x from mean/cov
% xs should be row-per-observation, column per variable
% mean should be a row vector

means = repmat(mean,size(xs,1),1);
size(means)
size(cov)
di = (xs-means);
size(di)
da = di*pinv(cov);

N = size(xs,1);

for j=1:3,
   dz(j,:) = (da(:,j).*di(:,j))';
end

d = sum(dz)';


% for i=1:N,
%   d(i,:) = da(i,:)*(di(i,:)');
% end




