I'm having some trouble in calculating the Mahalanobis Distance between a pair of objects. I followed the documentation of MATLAB where in order to calculate Mahalanobis Distance, I have to use pdist2: "D = pdist2(X,Y,'mahalanobis',C)"
A1=[75 87 90]; A2=[99 88 100];
C = nancov(A1,A2);
D = pdist2(A1,A2,'mahalanobis',C)
which gives me the error:
Error using pdist2 (line 282) The covariance matrix for the Mahalanobis metric must be a square matrix with the same number of columns as X. And it must be symmetric and positive definite.
on the other side if I try:
A1=[75 87 90]; A2=[99 88 100];
D = mahal(A1,A2)
I get:
Error using mahal (line 38) The number of rows of X must exceed the number of columns.
transposing A1,A2 I get a 3x1 matrix, but I'm pretty sure my value has to be one dimensional. Any help would be highly appreciated.