필터 지우기
필터 지우기

Error Index exceeds the number of array elements (0)

조회 수: 1 (최근 30일)
Francesco Lucarelli
Francesco Lucarelli 2021년 9월 6일
편집: Francesco Lucarelli 2021년 9월 6일
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

채택된 답변

Jan
Jan 2021년 9월 6일
ind = find(segment < 0.5);
lock(i) = ind1(ind(1));
If there is no element in segment, which is smaller than 0.5, ind is empty. Then you cannot access ind(1).
I cannot guess, what you want to write into lock(i) in this case.
  댓글 수: 2
Francesco Lucarelli
Francesco Lucarelli 2021년 9월 6일
i want to write the location of the element before the peak that is smaller than 0.5
It's weird that is empty because i can find the peak reference point, and there are for sure points before that peak which are smaller than 0.5
Do you think my code is inefficient in that way?
Thanks for your answer
Francesco Lucarelli
Francesco Lucarelli 2021년 9월 6일
편집: Francesco Lucarelli 2021년 9월 6일
Thanks a lot for your help.
I increased the number of points to check before the peak, and i solved the issue.
Thanks
Regards,
Francesco

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by