Reputation: 15
I have a 21x5 sized matrix (top5features) containing values for 5 different feature types extracted from 21 cancer nodules. I am trying to apply principal component analysis on my data and plotting the results, but am having trouble understanding how to do so. The following is my code so far, but it only plots a portion of the data and I do not believe it is what I am going for:
top5features = features(1:21,[42 55 61 62 60]);
[W, pc] = princomp(top5features);
pc = pc'; W = W';
plot(pc(1,:),pc(2,:),'.');
title('{\bf PCA} of Top 5 Features')
My goal is to make the plot so that it has 21 points, with each point pertaining to a specific nodule. These 21 nodules are also divided into two groups, and if possible I would like to color code them according to the group they belong to. I am somewhat of a beginner using Matlab and any help would be appreciated.
Upvotes: 1
Views: 8398
Reputation: 104464
Given your comments, the first 10 columns of your PCA decomposed data denote one group while the last 11 columns of your PCA decomposed data denote another group. This can simply be done in a single plot
command like so, using your code earlier:
%// Your code
top5features = features(1:21,[42 55 61 62 60]);
[W, pc] = princomp(top5features);
pc = pc'; W = W';
%// Group 1
group1 = pc(:,1:10);
%// Group 2
group2 = pc(:,11:21);
%// Plot as separate colours
plot(group1(1,:), group1(2,:), 'b.', group2(1,:), group2(2,:), 'r.');
title('{\bf PCA} of Top 5 Features')
legend('Group 1', 'Group 2');
The above code first separates your PCA reduced data into the two groups that you have specified. Next, we use a single plot
command to plot both groups together on a single plot but we colour differentiate them. Blue is for group 1 while red is for group 2. We place dot markers at each of the points. As a bonus, we add in a legend that denotes which group each point belongs to.
Hope this helps!
Upvotes: 3