I have this error : Reference to non-existent field 'mat'.
Show older comments
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]
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!