What does this error mean? Error ??? Index exceeds matrix dimensions.. Code included.
1 次查看(过去 30 天)
显示 更早的评论
close all;
clear all;
dbstop if error
lambda2 = [2 4 6 8];
theta2 = [0*pi/180, 45*pi/180, 90*pi/180, 135*pi/180, 180*pi/180, 225*pi/180, 270*pi/180, 315*pi/180];
no_lamd = 4;
no_theta = 8;
psi = [0 pi/2];
gamma = 0.5;
bw = 1;
N = 1;
%%%%%%%%%%%%%%%%%%%%%%%%
ext = '.bmp';
dirr = 'D:\GPDSdataset\';
[tr_data] = textread('trainfile_source.txt','%s'); %train
[mtr ntr] = size(tr_data);%mtr
%assign class no
model = 100;
train = 5;
cnt = 0;
for i = 1:5:5*model
cnt = cnt + 1;
for j = 0:1:4
ts_class(i+j)=cnt;
end
end
save ts_class ts_class
%select train image
model = 100;
cnt1 = 0;
cnt2 = 0;
for j = 1:20:20*model
for i = 0:1:4
cnt1 = cnt1+1;
AR_train(cnt1) = tr_data(j+i);%(THIS IS THE ERROR)
end
cnt2 = cnt2+1;
AR_test(cnt2) = tr_data(j+5);
end
size (AR_train');
size (AR_test');
0 个评论
回答(1 个)
Paulo Silva
2011-8-31
The error message tells all you need to know, you are requesting one index bigger than the maximum index of the matrix, I can't test your code, change the part of the loop to:
numel(AR_train) %this value gives you the maximum index for AR_train
numel(tr_data) %this value gives you the maximum index for tr_data
for i = 0:1:4
cnt1 = cnt1+1 %remove the ;
j+i %add this to monitor the j+i value
AR_train(cnt1) = tr_data(j+i);%(THIS IS THE ERROR)
end
run the code and look at the values that appear on your workspace, cnt1 can't be bigger than numel(AR_train), and j+i can't be bigger than numel(tr_data)
2 个评论
Paulo Silva
2011-8-31
Ok looking better at it you just need to look at the variables you get after the error occurrence, all the clues are there, also get the values:
numel(AR_train) %this value gives you the maximum index for AR_train
numel(tr_data) %this value gives you the maximum index for tr_data
and see if the problem is with AR_train(cnt1) or with data(j+i)
to solve the problem just correct the index values so it never goes beyond the maximum index of the variable
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!