pcomp.m
来自「wang xiao ping 版遗传算法」· M 代码 · 共 53 行
M
53 行
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 + =
减小字号Ctrl + -
显示快捷键?