I have this error : Reference to non-existent field 'mat'.
2 次查看(过去 30 天)
显示 更早的评论
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]
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!