⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcomp.m

📁 王小平《遗传算法——理论、应用与软件实现》随书光盘
💻 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 + -