principal component analysis loading plots *Advanced*
10 views (last 30 days)
Show older comments
Hi all,
I am wondering if there is anyone here that is really good with PCA on Matlab and coding. having an issue with my current PCA plot not showing the wavenumber in relation to absorbance on this plot. My PCA involves taking two different spectra and analysing their absorbance with respect to what kind of group of acrylic paint they come from. My program gives the first image showing a flat PCA plot with No PC3 component since the principal component of the wavenumber was not included.
I want to replicate something shown from Image 2 with my PCA plots where the different spectra are shown including the principal component of wavenumber.
I am unsure how to theoretically do this on Matlab?
I'm sorry but I'm going to have to attach my entire code here to show how I managed to graph this.
If this huge chunk of code is hard to interpret I can send some more data and show step by step how this program works.
Thanks for the help
file=readmatrix('Set_13_14.xlsx') %File read
obs=file'
%a = ones(1682,1) + (0:2); % change 4 to 1682 for your data
%grp = categorical(a(:), [1 2 3], ["Akzo", "Akzoo", "Akzooo"]) %Sets the different groups used such as Set10 and Set11 for IR spectra
part1 = repmat({'Set'},1682,1);
part2 = repmat({'Sett'},1601,1);
%part3 = repmat({'Settt'},1682,1);
grp = categorical([part1; part2]);
[U,S,V]=svd(obs,'econ');
figure;
subplot(1,2,1)
semilogy(diag(S), 'k-o','LineWidth',2.5)
set(gca,'FontSize',15),axis tight, grid on
subplot(1,2,2)
plot(cumsum(diag(S))./sum(diag(S)),'k-o','LineWidth',2.5)
set(gca,'FontSize',15), axis tight, grid on
figure, hold on
for i=1:size(obs,1)
x=V(:,1)'*obs(i,:)';
y=V(:,2)'*obs(i,:)';
z=V(:,3)'*obs(i,:)';
if grp(i)=='Set' %Decides which group will be used from the categorical array
plot3(x,y,z,'rx','Linewidth',3);
elseif grp(i)=='Sett'
plot3(x,y,z,'bo','LineWidth',3);
%elseif grp(i)=='Settt'
%plot3(x,y,z,'gx','LineWidth',3);
end
end
xlabel('PC1'), ylabel('PC2'), zlabel('PC3')
view(85,25), grid on, set(gca,'FontSize',15)
0 Comments
Answers (0)
See Also
Categories
Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!