📄 pca_new_final.m
字号:
function [x,vec]=pca_new_final(data)
% Remember that each column of the data matrix(input matrix) represent one image or pattern
[r,c]=size(data);
% Compute the mean of the data matrix "The mean of each row"
m=mean(data')';
% Subtract the mean from each image
d=data-repmat(m,1,c);
% Compute the covariance matrix (co)
co=d*d';
% Compute the eigen values and eigen vectors of the covariance matrix
[eigvector,eigvl]=eig(co);
% Sort the eigen vectors according to the eigen values
eigvalue = diag(eigvl);
[junk, index] = sort(-eigvalue);
eigvalue = eigvalue(index);
eigvector = eigvector(:, index);
% Compute the number of eigen values that greater than zero
count1=0;
for i=1:size(eigvalue,1)
if(eigvalue(i)>0)
count1=count1+1;
end
end
% We can use all the eigen vectors but this method will increase the
% computation time and complixity
%vec=eigvector(:,:);
% And also we can use the eigen vectors that the corresponding eigen values is greater than zero and this method will decrease the
% computation time and complixity
vec=eigvector(:,1:count1);
% Compute the feature matrix (the space that will use it to project the testing image on it)
x=vec'*d;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -