


PCASVD Principal Components Analysis via (mean-subtracted) SVD. PROJ = PCASVD(DATA), where DATA is an M x N matrix, returns the M x N matrix PROJ where the (M,N)th entry is the projection of the Mth row of DATA onto the Nth eigenvector of the covariance matrix formed from the rows of DATA. [PROJ,U,S,V] = PCASVD(DATA) also returns matrices U, S, V such that DATA = U * S * V' and PROJ = DATA * V. All of these computations are generally performed taking the mean over all rows of the matrix DATA to be the zero vector. This is therefore enforced if it is not already the case.


0001 function [proj,u,s,v] = pcasvd(data) 0002 %PCASVD Principal Components Analysis via (mean-subtracted) SVD. 0003 % PROJ = PCASVD(DATA), where DATA is an M x N matrix, returns the M x N 0004 % matrix PROJ where the (M,N)th entry is the projection of the Mth row 0005 % of DATA onto the Nth eigenvector of the covariance matrix formed from 0006 % the rows of DATA. 0007 % 0008 % [PROJ,U,S,V] = PCASVD(DATA) also returns matrices U, S, V such that 0009 % DATA = U * S * V' and PROJ = DATA * V. 0010 % 0011 % All of these computations are generally performed taking the mean over 0012 % all rows of the matrix DATA to be the zero vector. This is therefore 0013 % enforced if it is not already the case. 0014 0015 % Very simple code -- basically just a macro. 0016 data = detrend(data, 'constant'); % remove mean row 0017 [u,s,v] = svd(data, 0); % SVD the data matrix 0018 proj = data * v; % compute (mean-subtracted) pca projections?