??? Index exceeds matrix dimensions

hi, can anyone help me with this error ??? Index exceeds matrix dimensions..here is my code
close all;
clear all;
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, tr_class, x, y, answer] = textread('train_file.txt','%s %d %f %d %s'); %train
[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);
end
cnt2 = cnt2+1;
AR_test(cnt2) = tr_data(j+5);
end
size(AR_train');
size(AR_test');
??? Index exceeds matrix dimensions.

댓글 수: 3

Jan
Jan 2011년 8월 26일
@Mo: Have you read a little bit in this forum before posting the first time? We ask the authors again and again and again to format the code, such that it is readable. Either start the code lines by two spaces, or mark the code and hit the "{} Code" button. There is a link called "Markup" on this page, which explains the details. And Oleg spent some time to create this nice tutorial: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup .
Then it would be more efficient, if you post the line, which causes the error. Although the contributors are very enganged to fix bugs, but it is your turn to describe it as good as possible.
Mo
Mo 2011년 8월 26일
Dear Jan, hope this is readable, ive also mention which line that causes the error,hope to hear from you soon,tq
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');
Sean de Wolski
Sean de Wolski 2011년 8월 26일
The error message probably says what line the indexing error is on as well, please report that.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2011년 8월 26일

0 개 추천

Using the debugger would lead you to a solution efficiently:
dbstop if error
Then start the program. Now MATLAB stops, when the error occurs and you can inspect the current values of the variables in the command window or workspace browser. Finally you can find out by yourself, which index exceeds which dimension of which variable.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

Mo
2011년 8월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by