MATLAB Answers

PCA Plot Script/Synthax

3 views (last 30 days)
FkBang
FkBang on 1 Oct 2020
Answered: Gaurav Garg on 14 Oct 2020
Hi everyone. Sorry but I am very new to Matlab. The data I am working with has 10 variables and 31 observations. The 11th column is one of two categories to which each of these observations belong. I am using PCA to determine which of these 10 variables are most influential (or responsible for the most variance). I would like to get a 3D plot of the first 3 Principal components. Please, see below my script for this task.
[coeff,score,latent,tsquared,explained,mu] = pca(Values(:,1:10), 'NumComponents', 10)
y = Values(:,11);
scatter3(Values(:,1),Values(:,2),Values(:,3), 20, y, 'filled')
colormap(jet);
axis equal
xlabel('1st Principal Component')
ylabel('2nd Principal Component')
zlabel('3rd Principal Component')
Note: I imported the observations from a csv file as “Values” (49x11) and the variables as “Parameters” (1x11).
Below is what the above script produces:
I was hoping to get the points for the various variables in the plot in different colours to be able to tell which variable is where. At the moment it’s only the two categories that have been colour coded and not the variables. I hope there is a way to get these variables colour coded.I would appreciate it very much if I could get the correct script for this. Thanks a lot in advance.

  0 Comments

Sign in to comment.

Accepted Answer

Gaurav Garg
Gaurav Garg on 14 Oct 2020
Hi,
As can be seen in
scatter3(Values(:,1),Values(:,2),Values(:,3), 20, y, 'filled')
You are trying to plot y, which represents the categories of the observations.
Insted of plotting y, you will be needing to plot either of the following variables -
coeff,score,latent,tsquared,explained,mu

  0 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!