Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Error using - Matrix dimensions must agree. Error in Eigenfaces (line 14) t=double(z(i,:))-m;

1 回表示 (過去 30 日間)
Bereket Ayalew
Bereket Ayalew 2019 年 5 月 19 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
function [ ] = Eigenfaces( )
z=[];
ta=[];
for ii=1:100
str=int2str(ii);
str=strcat(str,'.jpg');
im=imread(str);
im=rgb2gray(im);
im=imresize(im,[256 256]);
temp=reshape(im,65536,1);
z=[z temp];m=mean(z,2);
end
for i=1:size(z,2)
t=double(z(i,:))-m;
ta=[ta t];
end
R=ta'*ta;
[v,d]=eig(R);
L_eig_vec=[];
for i=1:size(v,2)
if(d(i,i)>1)
L_eig_vec=[ L_eig_vec ; v(:,i) ];
end
end
Eigenfaces = ta*L_eig_vec;
disp('eig finished');
projectedimages = [];
Train_Number = size(ta,2);
for i = 1 : Train_Number
temp = Eigenfaces'*ta(:,i); %he
projectedimages = [projectedimages temp];
end
target=eye(Train_Number);
save latest.mat
end

回答 (2 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019 年 5 月 20 日
編集済み: Sulaymon Eshkabilov 2019 年 5 月 20 日
Hi,
Here is the corrected answer for MATLAB 2013 version:
function [ ] = Eigenfaces( )
z=[];
ta=[];
for ii=1:100
str=int2str(ii);
str=strcat(str,'.jpg');
im=imread(str);
im=rgb2gray(im);
im=imresize(im,[256 256]);
temp=reshape(im,65536,1);
z=[z temp]; m=mean(z,2);
end
for i=1:size(z,2)
t=double(z(:,i))-m;
ta=[ta t];
end
R=ta'*ta;
[v,d]=eig(R, R, 'chol');
L_eig_vec=[];
for i=1:size(v,2)
if(d(i,i)>1)
L_eig_vec=[ L_eig_vec ; v(i,i) ];
end
end
Eigenfaces = ta*L_eig_vec;
disp('eig finished');
projectedimages = [];
Train_Number = size(ta,2);
for i = 1 : Train_Number
temp = Eigenfaces'*ta(:,i);
projectedimages = [projectedimages temp];
end
target=eye(Train_Number);
save latest.mat
end
Good luck.

Geoff Hayes
Geoff Hayes 2019 年 5 月 20 日
Bereket - the error message is telling you that the matrices upon which you are executing the difference (of), are of different dimensions. When subtracting one matrix from an another, both must have the same number of rows and columns. In the case of your code
t=double(z(i,:))-m;
what are the dimensions of z(i,:) compared with the dimensions of m? Or are you expecting m to be a scalar?
Also, you have a line of code
Eigenfaces = ta*L_eig_vec;
where Eignefaces is the name of your function. Is this intentional? Or should this just be local variable named differently from the function?

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by