Error Index exceeds the number of array elements (0)
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Francesco Lucarelli
el 6 de Sept. de 2021
Editada: Francesco Lucarelli
el 6 de Sept. de 2021
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
0 comentarios
Respuesta aceptada
Jan
el 6 de Sept. de 2021
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 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!