error occured during selection of random images
1 view (last 30 days)
Show older comments
Index exceeds matrix dimensions.
Error in tt (line 18)
fn = fullfile(P,D,F{ii});
clc;
clear all;
tic;
%% Training images
id_test = 0;
id_train = 0;
P = 'ROIBintrain'; % i.e. relative/absolute path to where the subfolders are.
for ii = 1:10 % no of classes
D = sprintf('%u',ii);
S = dir(fullfile(P,D,'*.bmp')); % get all filenames in subfolder
N = numel(S);
X = randperm(N);
F = {S(X(1:8)).name}; % randomly select 8 filenames.
for jj = 1:numel(F) % no of images per class
fn = fullfile(P,D,F{ii});
im = imread(fn);
X = double(im);
X = imresize(X,[100 120],'bilinear'); %300 250
id_train = id_train+1;
traindata{id_train}=ext_vein(X,1);
traindata = traindata';
% only four minutie is taken from one image
reduced_traindata = cellfun(@(M) M(1:min(end,4), :), traindata, 'uniform', 0);
end
end
%% Testing images
d=[];
P = 'ROIBintrain'; % i.e. relative/absolute path to where the subfolders are.
for ii = 1:10 % no of classes
D = sprintf('%u',ii);
S = dir(fullfile(P,D,'*.bmp')); % get all filenames in subfolder
N = numel(S);
X = randperm(N);
F = {S(X(1:8)).name}; % randomly select 8 filenames.
for jj = 1:numel(F) %no of images per class
fn = fullfile(P,D,F{ii});
im = imread(fn);
X = double(im);
X = imresize(X,[100 120],'bilinear'); %300 250
id_test = id_test+1;
testdata{id_test}=ext_vein(X,1);
testdata = testdata';
% only four minutie is taken from one image
reduced_testdata = cellfun(@(M) M(1:min(end,4), :), testdata, 'uniform', 0);
end
end
%%
save('db1.mat','reduced_testdata');
save('db2.mat','reduced_traindata');
toc
0 Comments
Answers (1)
KALYAN ACHARJYA
on 13 Feb 2020
Edited: KALYAN ACHARJYA
on 13 Feb 2020
Beacuse length of F / fullfile total images is less than 10, check and verify
6 Comments
KALYAN ACHARJYA
on 13 Feb 2020
In the initial for loop you have defined ii = 1:10, when ii reached to 9, how it gets the F{9}, its having length only 8, hence it shows the error in that line, change the ii to 8, may be it works (to test)
Error in tt (line 18)
fn = fullfile(P,D,F{ii});
See Also
Categories
Find more on Matrix Indexing 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!