Note that there are some explanatory texts on larger screens.

plurals
  1. POMahalanobis distance between two vectors
    primarykey
    data
    text
    <p>I tried to apply <a href="http://www.mathworks.com/help/stats/mahal.html" rel="nofollow"><code>mahal</code></a> to calculate the <a href="http://en.wikipedia.org/wiki/Mahalanobis_distance" rel="nofollow">Mahalanobis distance</a> between 2 row-vectors of 27 variables, <em>i.e</em> <code>mahal(X, Y)</code>, where <code>X</code> and <code>Y</code> are the two vectors. However, it comes up with an error:</p> <blockquote> <p><code>The number of rows of X must exceed the number of columns.</code></p> </blockquote> <p>After a few minutes of research I got that I can't use it like this, but I'm still not sure sure why. Can some explain it to me?</p> <p>Also I have below an example of <code>mahal</code> method :</p> <pre><code>&gt;&gt; mahal([1.55 5 32],[5.76 43 34; 6.7 32 5; 3 3 5; 34 12 6;]) ans = 11.1706 </code></pre> <p>Can someone clarify how MATLAB calculate the answer in this case?</p> <p><strong>Edit:</strong><br/> I found this code that calculate the mahalanobis distance:</p> <pre><code>S = cov(X); mu = mean(X); d = (Y-mu)*inv(S)*(Y-mu)' d = ((Y-mu)/S)*(Y-mu)'; % &lt;-- Mathworks prefers this way </code></pre> <p>I tested it on <code>[1.55 5 32]</code>, and <code>[5.76 43 34; 6.7 32 5; 3 3 5; 34 12 6;]</code> and it gave me the same result as if I used the <code>mahal</code> function (11.1706), and I tried to calculate the distance between the 2 vectors of 27 variables and it works. What do you think about it? Can I count on this solution since the <code>mahal</code> function can't do what I need?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload