Principal Component Analysis (PCA) [scores] = princomp2(X, flag_rotate = 0) [scores, loadings] = princomp2(X, flag_rotate = 0) [scores, loadings, lambdas] = princomp2(X, flag_rotate = 0) Explanation: PCA formula: scores = X*loadings Loadings are the eigenvectors of the X's scatter matrix. The scatter matrix is defined ad X'*X, a simmetric positive definite or semi-definite with rank r <= d Inputs: X: [n][d] dataset matrix, columns stand for features and rows stand for observations Outputs: scores: [n][r] PCA scores. loadings: [d][r] loadings matrix (r is the rank of the dataset's scatter matrix (see below for scatter matrix definition). Loadings are actually the eigenvectors of the scatter matrix. lambdas: [r][1] contains the eigenvalues of the scatter matrix. Note: the loadings vectors sometimes happen to point at the opposite directions of those obtaines by MATLAB's princomp() (not really a problem).