title: Why different result with PCA and SVD in Matlab?
body: <p>I have implemented my PCA function in Matlab in the following way:</p>
  
  <pre><code>function e = myPCA(X)
  [D, N] = size(X);
  m = mean(X, 2);
  X = X - repmat(m, 1, N);
  [e, ~, ~] = svd(X,'econ');
  end
  </code></pre>
  
  <p>When I use now the built in Matlab function <code>[e, ~, ~] = pca(X');</code> I'm getting the same absolute values as with my function but for some columns of U the sign is flipped.</p>
  
  <p>Which ones is the right way to go and why is there this difference in sign?</p>