From your code it seems like you are taking the covariance of the labels
, not the trainingData
. I believe the point of PCA is in determining the greatest variance in some N (N = 10 here) number of subspaces of your data.
Your covariance matrix should be 900x900 (if 900 is the dimension of each image, a result of having 30x30 pixel images I assume.) Where the diagonal elements [i,i]
of covaraincex
gives the variance of that pixel for all training samples, and off diagonal [i,j]
give the covariance between pixel i
and pixel j
. This should be a diagonal matrix as [i,j] == [j,i].
Furthermore when calling eigs(covariancex,N)
, N should be 10 instead of 40 if you want to reduce the dimension to 10.