Perform Principal Components Analysis (PCA) in MATLAB using the values from the X and Y files.
Plot wherever is necessary (original data, data with the means subtracted, eigenvectors, data using both eigenvectors, reconstruction from the data using a single eigenvector etc.).
Add comments to your code.
Find the MATLAB script for PCA analysis:
x=load(‘X.txt’); % Loading X data
y=load(‘Y.txt’); % Loading Y data
[coeff,score,latent] = pca([x,y]); % Perfomring principal compnent analysis
% latent => Principal component variances, that is the eigenvalues of the covariance matrix of data, returned as a column vector.
% score => Principal component scores, returned as a matrix. Rows of score correspond to observations, and columns to components.
% coeff => Principal component coefficients, returned as a p-by-p matrix. Each column of coeff contains coefficients for one principal component. The columns are in the order of descending component variance, latent.
Xcentered = score*coeff’; % Reconstructing the data
% Visualize both the orthonormal principal component coefficients for each variable
% and the principal component scores for each observation in a single plot.