📄 pcomp.m
字号:
function [pc,coeffs,prinvar]=pcomp(sdata)
%
% Function to calculate pca coefficients
% pc - contains the transformed data
% coeffs - contains the coefficients of each principal component
% prinvar - contains the variances
%
% call:
% [pc coefs prinval]=pcomp(data);
%
[D L]=size(sdata);
%
% Calculate the covariance matrix of 'sdata'
%
covmat=corrcoef(sdata);
%
% Calculate the eignvalues and eignvectors of the covariance
% matrix
%
[coeffs D]=eig(covmat,'nobalance');
%
% Take the diagonal elements of the eigenvalue matrix D
% put them in the principal components variance matrix prinvar
%
prinvar=diag(D);
%
% Rearrange this matrix so that the most significant principal
% component comes first
%
prinvar=flipud(prinvar);
%
% Cumulative percentage
%
prinvar=(cumsum(prinvar)./sum(prinvar)).*100;
coeffs=fliplr(coeffs);
%
% Calculate transformed data
%
pc=sdata*coeffs;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -