필터 지우기
필터 지우기

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 (최근 30일)
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

채택된 답변

Stephen23
Stephen23 2018년 3월 1일
편집: Stephen23 2018년 3월 1일
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

추가 답변 (1개)

wisam kh
wisam kh 2018년 5월 12일
Hello when I try this code I got this error
Error in build_db (line 9) img = imread(filename);
how can I solve it, help me please

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by