index exceeds matrix dimension problem

2 views (last 30 days)
Ndifreke Nyah
Ndifreke Nyah on 31 Dec 2014
Edited: per isakson on 1 Jan 2015
I got 'index exceeds matrix dimension problem' while trying to convert test and training face datasets to image and labels when i run the code below. The structure of the datasets and vaiable is at the end of this code. please help. the error line is Bold(*).thank you.
% open test tst_data - testing data
f = fopen('tst_data.mat', 'r');
[aa,count] = fread(f,4,'int32');
g = fopen('tst_data.mat','r');
[ll,count] = fread(g,2,'int32');
fprintf(1,'Starting to convert Test FACE images (prints 13 dots) \n');
n = 38;
Df = cell(1,13);
for d= 0:12,
Df{d + 1} = dir(['images_tst' num2str(d) '.ascii']);
end;
for i=1:13,
fprintf('.');
rawimages = fread(f,32*32*n,'uchar');
rawlabels = fread(g,n,'uchar');
rawimages = reshape(rawimages,32*32,n);
for j=1:n,
*fprintf(Df{rawlabels(j+1)},'%3d ',rawimages(:,j));* % <<<<<<<<
fprintf(Df{rawlabels(j+1)},'\n');
end;
end;
fprintf(1,'\n');
for d=0: 12,
fclose(Df{d+1});
D = load(['images_tst' int2str(d) '.ascii'],'-ascii');
fprintf('%5d imagess of class %d\n',size(D,1),d);
save(['images_tst' int2str(d) '.mat'],'D','-mat');
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% open train trg_data - training data
f = fopen('trg_data.mat', 'r');
[a,count] = fread(f,4,'int32');
g = fopen('trg_data.mat','r');
[l,count] = fread(g,2,'int32');
fprintf(1,'Starting to convert Test FACE images (prints 52 dots) \n');
n = 38;
Df_trg = cell(1,52);
for d= 0:51,
Df_trg{d + 1} = dir(['images_trg' num2str(d) '.ascii']);
end;
for i=1:52,
fprintf('.');
rawimages_trg = fread(f,32*32*n,'uchar');
rawlabels_trg = fread(g,n,'uchar');
rawimages_trg = reshape(rawimages_trg,32*32,n);
for j=1:n,
*fprintf(Df_trg{rawlabels_trg(j)+1},'%3d ',rawimages_trg(:,j));*%%%
fprintf(Df_trg{rawlabels_trg(j)+1},'\n');
end;
end;
fprintf(1,'\n');
for d=0:51,
fclose(Df_trg{d+1});
D = load(['images_trg' num2str(d) '.ascii'],'-ascii');
fprintf('%5d images of class %d\n',size(D,1),d);
save(['images_trg' num2str(d) '.mat'],'D','-mat');
end;
--------------------------------------------------------------------
Name Size Bytes Class Attributes
Df 1x13 4940 cell
I_trg 32x32 1024 uint8
I_tst 32x32 1024 uint8
Id_tst 1024x1 8192 double
aa 4x1 32 double
count 1x1 8 double
d 1x1 8 double
f 1x1 8 double
files_img 1976x1 800712 struct
files_img_t 494x1 200346 struct
g 1x1 8 double
i 1x1 8 double
i_trg 1x1 8 double
j 1x1 8 double
ll 2x1 16 double
m 1x1 8 double
n 1x1 8 double
np_img 1x1 8 double
np_img_t 1x1 8 double
pt_images 1x9 18 char
rawimages 1024x38 311296 double
rawlabels 38x1 304 double
trg_data 1024x1976 16187392 double
tst_data 1024x494 4046848 double
x_img 1x1 8 double
x_img_t 1x1 8 double
y_img 1x1 8 double
y_img_t 1x1
  1 Comment
per isakson
per isakson on 31 Dec 2014
Edited: per isakson on 31 Dec 2014
Not easy to say without running the code. Df_trg is not in the list. Anyhow, here are some links on debugging in Matlab

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!