0

For certain measurements i need to obtain only the numeric value of the first principal component from the matrix. Can someone please tell me how do i go about it?

Sid
  • 249
  • 5
  • 16
  • 4
    This question appears to be off-topic because it is about maths – Mitch Wheat Oct 01 '13 at 06:08
  • Have you tried to search for an answer before asking? There's a multitude of questions (with good answers!) even here in SO, *e.g* [this one](http://stackoverflow.com/questions/4402110/principal-component-analysis-in-matlab) and [this one](http://stackoverflow.com/questions/12688312/matlab-pca-analysis-and-reconstruction-of-multi-dimensional-data)... – Eitan T Oct 01 '13 at 06:14
  • @MitchWheat, given that this is a MATLAB question, I would think this counts as the programming question "which MATLAB commands should I use to achieve this" rather than the maths question "how do I calculate principal components". – Sam Roberts Oct 01 '13 at 09:05

1 Answers1

1

the most straight forward way is just to get the top eigenvector/value of your data's covariance matrix using eigs

say the data matrix x is N by D, or # of data by dimension of data

you can simply do

C = cov(X);
[V, D] = eigs(C, 1);

in fact, you can get the top k principal components by running

[V, D] = eigs(C, k);
prgao
  • 1,767
  • 14
  • 16
  • Prgao,I had used "eig" which gives dimension error if used like eig(C,k), but had missed out on the "eigs" prior to your post. Thank you so much it worked as desired. – Sid Dec 24 '13 at 02:05