Reputation: 21
I am new to Matlab and have some problems using built in packages for PCA reduction. I have 37 objects each represented by 161 dimensional vector, that means i have 161 x 37 matrix called P. I need to reduce vector dimension to 3. so that each object will be represented by 3 dimensional vector. I have tried something with princomp(P) but i don't know which output to take.
[COEFF,SCORE] = princomp(P); newData=SCORE(:,1:3);
I think newData are not the right vectors ?
Upvotes: 2
Views: 1118
Reputation: 4549
You have to transpose your data because princomp
expects observations on rows:
[COEFF,SCORE] = princomp(P.');
newData=SCORE(1:3.:).';
Alternatively you can use pca
function to give you only the first 3 principal components:
[COEFF,SCORE] = pca(P.', 'NumComponents', 3)
newData=SCORE.';
Upvotes: 2