title: Calculating the covariance of a 1000 5x5 matrices in matlab
body: <p>I have a 1000 5x5 matrices (<strong>Xm</strong>) like this:</p>
  
  <p><img src="https://i.stack.imgur.com/ek2ZS.png" alt="enter image description here"></p>
  
  <p>Each $(x_ij)<em>m$ is a point estimate drawn from a distribution. I'd like to calculate the covariance <code>cov</code> of each $x</em>{ij}$, where i=1..n, and j=1..n in the direction of the red arrow.</p>
  
  <p>For example the variance of $X_m$ is `var(X,0,3) which gives a 5x5 matrix of variances. Can I calculate the covariance in the same way?</p>
  
  <p><strong>Attempt at answer</strong></p>
  
  <p>So far I've done this:</p>
  
  <pre><code>for m=1:1000
  Xm_new(m,:)=reshape(Xm(:,:,m)',25,1);
  end
  
  cov(Xm_new)
  spy(Xm_new) gives me this unusual looking sparse matrix:
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/2J3Ea.png" alt="enter image description here"></p>