example75_eigenvalue.m

来自「是一个用MATLAB编的一个系统」· M 代码 · 共 35 行

M
35
字号
%%%example75_eigenvalue
b0(:,1)=reshape(double(rgb2gray(img1)),32*32,1);
b0(:,2)=reshape(double(rgb2gray(img2)),32*32,1);
%caculate the eigenvalues and the eigenvectors of the cov matrix
b=(b0(:,1)+b0(:,2))/2;
B1=b0';
C=cov(B1,1);
[V,D]=eig(C);
W0=V;
[m,n]=size(b0);

for j=1:m-1
    for i=1:m-j
        if D(i,i)<D(i+1,i+1)
            temp1=D(i,i);
            D(i,i)=D(i+1,i+1);
            D(i+1,i+1)=temp1;
            temp2=W0(:,i);
            W0(:,i)=W0(:,i+1);
            W0(:,i+1)=temp2;
        end
    end
end

cpts=16;
i=1:cpts;
W(:,i)=W0(:,i);
    
T=ones(16,1);
for x=1:16
    T(x)=D(x,x);
end
figure('name','前16个特征值','numbertitle','off');
x=1:16;
plot(x,T(x));

⌨️ 快捷键说明

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