while using for loop in following function some blank cells are come into output matrix like [ ] [ ] [ ]. I dont understand where i wrong in for loop
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Balaji M. Sontakke
el 1 de Mzo. de 2018
Comentada: Stephen23
el 12 de Mayo de 2018
function build_db(ICount, JCount)
p=0;
path = 'E:\MATLAB\R2016b\bin\img\PCA\my_PhD_Programs\minuite\FVC2002\DB1_B\'
for i=1:ICount % 10
for j=1:JCount % 8
filename=[path,num2str(i) '_' num2str(j) '.bmp'];
img = imread(filename);
img = imresize(img,[374 388]);
p=p+1;
if ndims(img) == 3;
img = rgb2gray(img);
end % colour image
disp(['extracting features from ' filename ' ...']);
if j<4
testdata{p}=ext_vein(img,1);
else
traindata{p}=ext_vein(img,1);
end
end
end
save('db1.mat','testdata');
save('db2.mat','traindata');
end
%********************************************** Function invoked *******************
build_db(2,8); %THIS WILL TAKE ABOUT 30 MINUTES
load('db1.mat');
load('db2.mat');
testdata = testdata'; % Adjust matrix dimension
testfeature = cell2mat(testdata); % Convert cell array to matrix
traindata = traindata';
trainfeature = cell2mat(traindata);
dist = pdist2(testfeature,trainfeature,'euclidean'); % compute euclidian distance
%*****************************************OUTPUT We Get *********************************************** Testdata matrix contains following values
54x6 double
44x6 double
44x6 double
[]
[]
[]
[]
[]
44x6 double
60x6 double
38x6 double
and traindata contains following values
[]
[]
[]
50x6 double
47x6 double
38x6 double
31x6 double
43x6 double
[]
[]
[]
35x6 double
37x6 double
39x6 double
27x6 double
27x6 double
0 comentarios
Respuesta aceptada
Stephen23
el 1 de Mzo. de 2018
Editada: Stephen23
el 1 de Mzo. de 2018
You use the variable p as an index into both the training and test data cell arrays, so when you have incremented the training data index it clearly also increments the test index, because it is the same index!
The solution is simple: replace p with two separate indices, and increment them independently:
id_test = 0;
id_train = 0;
for ...
for ...
...
if j<4
id_test = id_test+1;
testdata{id_test} = ...;
else
id_train = id_train+1;
traindata{id_train} = ...;
end
...
end
end
Más respuestas (1)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!