MATLAB Answers

Hello, I was wondering why my last figure in this code keeps giving me a 3D graph instead of a 2D

11 views (last 30 days)
Connor Miller
Connor Miller on 27 Oct 2020 at 15:30
Commented: Connor Miller on 27 Oct 2020 at 15:36
clear all, close all, clc
filename = 'PCA1.xlsx';
a = xlsread(filename,"CAP",'B:B')
b = xlsread(filename,"CAP",'C:C')
X = bsxfun(@minus,a,mean(a))
Y = bsxfun(@minus,b,mean(b))
Z = [X,Y]
[U,S,V] = svd(Z,"econ")
figure
subplot(1,2,1)
semilogx(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
set(gcf,'Position',[1400 100 3*600 3*250])
figure, hold on
for i=1:size(Z,1)
x = V(:,1)'*Z(i,:)';
y = V(:,2)'*Z(i,:)';
plot(x,y,'r-o','LineWidth',3)
xlabel('PC1')
ylabel('PC2')
view(85,25), grid on, set(gca,'FontSize',15)
set(gcf,'Position',[1400 100 1200 1600])
end

  0 Comments

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by