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!