Help fixing error message: Index in position 2 exceeds array bounds (must not exceed 1).

Hi All,
Can someone please help me with my code. I get the error message "Index in position 2 exceeds array bounds (must not exceed 1)." at this point of my code, and I am not sure how to fix it:
dataBin = data(1:binWidth, jj); %data in 1 bin
My overall code:
t1 = 20; %start time, seconds
t2 = 30; %end time, seconds
ind1 = find(tim_trl>=t1, 1);
ind2 = find(tim_trl>=t2, 1); %10s time frame
time1 = tim_trl(ind1:ind2);
sampRate = 24414; %sampling freq (Hz), samples per sec
muaWindow = 0.001; %1ms window
binWidth = round(muaWindow*sampRate); %samples be 1ms
threshold = 0.018;
for jj = 1:16 %ch
data = AbData(ind1:ind2, jj);
for kk = 1:10000
abDataBin = data(1:binWidth,jj); %ab data in 1 bin
dataThreshold = find(abDataBin >= threshold); %find data points >= threshold %1 >thres; 0 <thres
mua(kk,jj) = sum(dataThreshold); %number of data over threshold per ch
end
end
Your help is appreciated. Cheers.

4 Comments

with the line:
data = AbData(ind1:ind2, jj);
You create an matrix of size (x,1), so you should remove the jj from the line:
abDataBin = data(1:binWidth,jj); -> abDataBin = data(1:binWidth);
That seems to fix it, but only 1 data bin gets stored in adBinData, when I need all 10000 bins. Essentially, abDataBin should be a matrix of 10000x16 (10000 bins of data, kk, per 16 columns, jj). I know I need to apply a shifting window (each bin needs to shift every "1:binWidth" data points), but I'm not sure how to do it. Any ideas?
Im not sure what you want, but your for loop for kk is not usefull. you only use kk for a matrix element and all these elements in the loop has the same value.
Sorry, I know I’m not being clear. I’ll try and simplify it. I have a set of neural data collected across 16 different channels. I have indexed the data so that I only analyse the last 10 seconds (matrix: 244141 x 16). I want to group the data into 10000 bins across these 16 channels (0.001ms long, which is essentially 24 data points (i.e. binWidth). Within the For loop, I need to create a sliding window that shifts every 24 points (already defined as binWidth) and sums the number of data points >=threshold per bin. Ultimately, I want to left with a matrix of 10000 x 16 (all 10000 bins across 16 channels). I hope this makes more sense.

Sign in to comment.

Answers (0)

Products

Release

R2019b

Asked:

NA
on 30 Jul 2020

Edited:

NA
on 30 Jul 2020

Community Treasure Hunt

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

Start Hunting!