What does this error mean? Error ??? Index exceeds matrix dimensions.. Code included.

조회 수: 1 (최근 30일)
Mo
Mo 2011년 8월 31일
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');

답변 (1개)

Paulo Silva
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
Mo
Mo 2011년 8월 31일
thanks paulo but which part of the code should i change to..tq
Paulo Silva
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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by