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

조회 수: 1 (최근 30일)
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

채택된 답변

Cris LaPierre
Cris LaPierre 2020년 10월 27일
편집: Cris LaPierre 2020년 10월 27일
Because your view command is changing the camera angle, resulting in a 3D view.
view(85,25)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by