title: Calculating Covariance Matrix in Matlab
body: <p>I am implementing a PCA algorithm in MATLAB. I see two different approaches to calculating the covariance matrix:</p>
  
  <pre><code>C = sampleMat.' * sampleMat ./ nSamples;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>C = cov(data);
  </code></pre>
  
  <p>What is the difference between these two methods?</p>
  
  <p><strong>PS 1:</strong> When I use <code>cov(data)</code> is that unnecessary:</p>
  
  <pre><code>meanSample = mean(data,1);
  data = data - repmat(data, nSamples, 1);
  </code></pre>
  
  <p><strong>PS 2:</strong></p>
  
  <p>At first approach should I use <code>nSamples</code> or <code>nSamples - 1</code>?</p>