Index exceeds the number of array elements (1000).

1 次查看(过去 30 天)
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 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by