필터 지우기
필터 지우기

I have this error : Reference to non-existent field 'mat'.

조회 수: 3 (최근 30일)
Im@
Im@ 2015년 3월 15일
답변: Jan 2015년 3월 15일
here is the code, I wanted to split the database into training and testing subsets. the error appears ince I run this : observation=dB.mat(k,:); in the code below
function [TrainDBN , TestDBN]=genererDB(dB,Pourcentage_Test)
mapping=getmapping(8,'u2');
V=[];
database=[];
% number of features
dB.classes=[];
classes=[];
dB.Nbofclasses=50;%number of classes
Pourcentage_Test= 0.3;
Pourcentage_Training= 70/100;
for i=1:50
for j=1:15
name=['S' num2str(i,'%02d') '_' num2str(j,'%02d') '.jpg'];
img=imread(name);
imgHist =lbp(img,1,8,mapping,'nh');
database=[database;imgHist];
imshow(img);
dB.NbImagesPerClass(i)=15;
classes=[classes;i];
dB.mat=database;
dB.classes=classes;
pause
end
J=randperm(dB.NbImagesPerClass);
for L=1:length(J)
if J(L)<=Pourcentage_Test*dB.NbImagesPerClass/100;
J(L)=0;
else
J(L)=1;
end
V=[V J];
end
V=V';
TrainDBN.mat=[];
TestDBN.mat=[];
TrainDBN.classes=[];
TestDBN.classes=[];
% Générer les bases d'apprentissage TrainDBN et de test TestDB
for k=1:length(V)
observation=dB.mat(k,:);
if(V(k)==1)
TrainDBN.mat=[TrainDBN.Mat; observation];
TrainDBN.classes=[TrainDBN.classes;dB.classes(k)];
else
TestDBN.mat=[TestDBN.mat; observation];
TestDBN.classes=[TestDBN.classes;dB.classes(k)];
end
end
TrainDBN.NbClasses=dB.Nbclasses;
TestDBN.NbClasses=dB.Nbclasses;
end
[EDITED, Jan, please use a proper code formatting - thanks]

채택된 답변

Jan
Jan 2015년 3월 15일
The variable dB.mat is created in the loop. It is strange, that it is missing later on. Therefore I suggest to use the debugger to find out, what's going on. E.g. type this in the command line:
dbstop if error
Then run the code again. When it stops at the error, inspect the contents of the variable dB.
Perhaps you did not save the code after you've edited it?

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by