Why different result with PCA and SVD in Matlab?

1 回表示 (過去 30 日間)
Sepp
Sepp 2015 年 7 月 28 日
編集済み: Sepp 2015 年 7 月 28 日
Hello
I have implemented my PCA function in Matlab in the following way:
function e = myPCA(X)
[D, N] = size(X);
m = mean(X, 2);
X = X - repmat(m, 1, N);
[e, ~, ~] = svd(X,'econ');
end
When I use now the built in Matlab function
[e, ~, ~] = pca(X');
I'm getting the same absolute values as with my function but for some columns of U the sign is flipped.
Which ones is the right way to go and why is there this difference in sign?
Edit: I'm interested in retrieving all the eigenvalues and eigenvectors of the covariance matrix. If I'm using Matlab's pca method the eigenvectors are the columns in "e" from [e, ~, ~] = pca(X');. Is this right? But how can I retrieve the eigenvalues?
I have another point: "Compute the Principal components and eigenvalues of the Covariance/Correlation matrix". Are the principal components equal to the eigenvectors? Should I use in this case the pca method or SVD method from Matlab or does it not matter?

回答 (0 件)

カテゴリ

Help Center および File ExchangeDimensionality Reduction and Feature Extraction についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by