Compute Pearson correlation avoiding zero values
<p>I have a sparse matrix <code>A(m,n)</code>, where <code>n</code> are the variables and <code>m</code> the observations. I want to compute the Pearson correlation among all the n variables.</p>

<p>I have some missing observations, e.g. if <code>A(2,3)</code> is not available it means that I don't have such observation, so if, for example, I need to compute the correlation between column 3 and column 4, I must discard row 2, even if <code>A(2,4)</code> is available. This is how Pearson correlation is normally computed.</p>

<p>In MATLAB, instead, the function <code>corrcoef()</code> consider all the values, including the missing ones (which are considered zeros). Is there a simple way to avoid this? A very similar question is available here <a href="https://stackoverflow.com/questions/7911052/pearson-correlation-without-using-zero-element-in-matlab">Pearson Correlation without using zero element in Matlab</a> but a working solution is provided just for the comparison among two vectors and not for a generic matrix <code>A(m,n)</code> where <code>n &gt; 2</code>.</p>