Error Index exceeds the number of array elements (0)
Show older comments
Hi all,
My code seems to have a problem but i'm not able to overcome it.
I have my stimulation signal (stimp). With findpeak i found a reference point.
My goal is to check from the referecne point, going backward 5 points, which is the first point which my signal goes below a certain treshould (0.5)
Code below:
[pks,loc]=findpeaks(stimp,'MinPeakHeight',2); %find peaks of stimulation bigger than 2mA
%code to detect the first peak
locp = loc(1);
k = 1;
for i = 2:numel(loc) %keep only first peak that has distance to next other peak >6samples
if abs(loc(i)-loc(i-1))>6
k = k+1;
locp(k) = loc(i);
end
end
%code to detect the first point before the first peak that is smaller than
%0.5
for i = 1:length(locp) %Starting from the peak, backward of 5 samples, find the first sample before the peak smaller than the threshold=0.5mA
ind1=locp(i):-1:locp(i)-5;
segment = stimp(ind1);
ind= find(segment<0.5);
lock(i) = ind1(ind(1));
end
I don't understand because sometimes is working, some other times no
the error is:
Index exceeds the number of array elements (0).
Error in Untitled (line 9)
lock(i) = ind1(ind(1));
Please find attached a copy of the stimulation signal= stimp
Can anyone help me with this?
Thanks a lot for your time
Regards,
Francesco
Accepted Answer
More Answers (0)
Categories
Find more on Descriptive Statistics 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!