Index exceeds the number of array elements (1000).

3 views (last 30 days)
Samantha Hessels
Samantha Hessels on 29 Jul 2020
Answered: Sriram Tadavarty on 29 Jul 2020
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));
Image Analyst
Image Analyst on 29 Jul 2020
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

Sign in to comment.

Answers (1)

Sriram Tadavarty
Sriram Tadavarty on 29 Jul 2020
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

Community Treasure Hunt

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

Start Hunting!