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

📄 pca.m

📁 主元分析(pca)的matlab程序,运算时间短,程序简单
💻 M
字号:
%P returns the load matrix of x;
%T returns the score matrix of x;
%W is the convert matrix from X to T;

function [Th,P,W] = pca(x,maxrank)

[m,n] = size(x);
if nargin == 2, i = min([n, m, maxrank]); else i = min([n m]); end

P = [];
Th = [];
W = [];

for h=1:i % for1
   Sell = mod(floor((rand(1,1)*10000)), n);
   t0 = x(:, Sell + 1);
   while (1)
      ph = x'*t0/(t0'*t0);
      ph = ph/sqrt(ph'*ph);
      th = x*ph/(ph'*ph);
      
      if((t0-th)'*(t0-th)<0.001)
         break;
      end
      t0 = th;
   end % end of while
   %compute the load vector of x
   
   if h==1
      Th = th;
      P = ph;
   else
      Th = [Th th];
      P = [P ph];
   end
   
   x = x - th*ph';
end % end of for1

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -