Index exceeds the number of array elements (1000).

조회 수: 6 (최근 30일)
Samantha Hessels
Samantha Hessels 2020년 7월 29일
답변: Sriram Tadavarty 2020년 7월 29일
sub = 1;
load subject1.mat
% veldat(hand): samples, joints, reps, tasks,sub
% oridat(eeg): samples, chs, reps, tasks
% 8 bandwidths
njoint = 10;
ntask = 6;
nrep = 30;
nch = 32;
nban = 8;
veldat = EEGdat;
oridat = gdat;
%%%%%%%%%%%%%%%%%%%%%%%%% EEG data %%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% averaged bandpower features within segments %%%%%%%
N = size(oridat,1); % number of samples
n = (1-1/4)*N/(N/4/4)+1;
sg = round(size(oridat,1)/4); % total 2s, pick 0.5s segment
ll = round((size(oridat,1)/4)/4); % 75% overlap
for task = 1:ntask
for rep = 1:nrep
for ch = 1:nch
edat = zscore(oridat(:,ch,rep,task)); % standardization
for i = 1:n
sg1 = (i-1)*ll+1;
sg2 = (i-1)*ll+sg;
segE(i,ch,rep,task) = bandpower(edat(sg1:sg2));
end
end
end
end
  댓글 수: 2
Samantha Hessels
Samantha Hessels 2020년 7월 29일
Because the index exceeds the array there is also an error in this line:
segE(i,ch,rep,task) = bandpower(edat(sg1:sg2));
Image Analyst
Image Analyst 2020년 7월 29일
Unfortunately you forgot to attach subject1.mat, so we don't know. All we know is that segE doesn't have dimensions as big as any of those indexes, and same for edat. Just do normal debugging to check out what the size of everything is and figure out why you're asking for some element that's beyond the end of the array. Attach subject1.mat if you need more help, after you read this link.
This one might also help: Debugging in MATLAB

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

답변 (1개)

Sriram Tadavarty
Sriram Tadavarty 2020년 7월 29일
Hi Samantha,
Yes, as mentioned by you in the comments. When ever there is an index accessing the array or matrix, beyond its size. You get indexing error.
For your problem here, without knowing much about what you are looking for, I suggest placing if condition before accessing the edat. Something like if sg1 <= length(edat) && sg2 <= length (edat), only then execute the command segE. This would avoide an indexing error.
Hope this helps. Regards, Sriram

카테고리

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