Please Help me with my code (Index exceeds matrix dimensions)
2 views (last 30 days)
Show older comments
I am not very good at explaining my problems so I will post the relevant parts of the code and the error message below and hope that someone can help. The error occurs in the 2nd to last line of code that I posted below. When I comment this line out the rest of the code runs flawlessly.
start1=400
start2=531
start3=663
start4=781
finish4=890
start1new = (start1*1800/120)
start2new = (start2*1800/120)
start3new = (start3*1800/120)
start4new = (start4*1800/120)
finish4new = (finish4*1800/120)
%Filtering EMG Data
[B,A]=butter(2,(2*30/1800),'high');
filtEMGdata = filtfilt(B,A,rawEMGdata);
filtEMGdata = abs(filtEMGdata);
[B,A]=butter(2,(2*10/1800),'low');
filtEMGdata=filtfilt(B,A,filtEMGdata);
%Normalized EMG Brackets
normGas_Med_EMG = [];
normGas_Lat_EMG = [];
normTA_EMG = [];
normPer_Long_EMG = [];
normSol_EMG = [];
%Normalized EMG data
normGas_Med_EMG(:,1) = downsample(interp(filtEMGdata(start1new:start2new,1),200),length(start1new:start2new));
normGas_Med_EMG(:,2) = downsample(interp(filtEMGdata(start2new:start3new,1),200),length(start2new:start3new));
normGas_Med_EMG(:,3) = downsample(interp(filtEMGdata(start3new:start4new,1),200),length(start3new:start4new));
aveGas_Med_EMG = mean(normGas_Med_EMG,2);
Here is the Error Message:
Index exceeds matrix dimensions.
Error in AnkleTapingStudy_EMG_CODE_2 (line 147)
normGas_Med_EMG(:,3) = downsample(interp(filtEMGdata(start3new:start4new,1),200),length(start3new:start4new));
I am confused because the first 2 lines under "Normalized EMG Data" work, but the 3rd does not. Why is this?
p.s. When I set "start4" to 697 the code runs, but anything greater or equal to 698 is an error message. The relevant information in my data is at frame 781. What should I do?
2 Comments
Answers (1)
Walter Roberson
on 14 Apr 2018
1800/120 = 15, so you are working with blocks of 15 samples per "start" value.
10467/15 = 697.8, so any "start" value greater than 697, when multiplied by 1800/120, is going to result in trying to index outside the data.
If you hope to reach 890 as the finish then your blocks cannot be more than 11 rather than 15.
0 Comments
See Also
Categories
Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!