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 Center および File ExchangeAxis Labels についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by