I have an n x p matrix - mX which is composed of n points in R^p.

I have another m x p matrix - mY which is composed of m reference points in R^p.

I would like to create an n x m matrix - mD which is the [Mahalanobis Distance](https://en.wikipedia.org/wiki/Mahalanobis_distance) matrix.

D(i, j) means the [Mahalanobis Distance](https://en.wikipedia.org/wiki/Mahalanobis_distance) between point i in mX, mX(i, :) and point j in mY, mY(j, :).

Namely, is computes the following:

```
mD(i, j) = (mX(i, :) - mY(j, :)) * inv(mC) * (mX(i, :) - mY(j, :)).';

```

Where mC is the given Mahalanobis Distance PSD Matrix.

It is easy to be done in a loop, is there a way to vectorize it?

Namely, is the a function which its inputs are mX, mY and mC and its output is mD and fully vectorized without using any MATLAB toolbox?

Thank You.