pca.m 839 B

123456789101112131415161718192021222324252627282930
  1. function [U, S] = pca(X)
  2. %PCA Run principal component analysis on the dataset X
  3. % [U, S, X] = pca(X) computes eigenvectors of the covariance matrix of X
  4. % Returns the eigenvectors U, the eigenvalues (on diagonal) in S
  5. %
  6. % Useful values
  7. [m, n] = size(X);
  8. % You need to return the following variables correctly.
  9. [U, S] = svd(X' * X / m);
  10. % ====================== YOUR CODE HERE ======================
  11. % Instructions: You should first compute the covariance matrix. Then, you
  12. % should use the "svd" function to compute the eigenvectors
  13. % and eigenvalues of the covariance matrix.
  14. %
  15. % Note: When computing the covariance matrix, remember to divide by m (the
  16. % number of examples).
  17. %
  18. % =========================================================================
  19. end