Filter löschen
Filter löschen

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

3 Ansichten (letzte 30 Tage)
Im@
Im@ am 15 Mär. 2015
Beantwortet: Jan am 15 Mär. 2015
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]

Akzeptierte Antwort

Jan
Jan am 15 Mär. 2015
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?

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by