Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

ZERO crossing with certain conditions

1 visualización (últimos 30 días)
Bran
Bran el 13 de Abr. de 2015
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
I am trying to write an algorithm which will look for zero crossings (or in my case crossing across a specific value) in my data and then keep only those points that are intercepted by values above a certain threshold; Here is the code I have written so far
Crossings=0;
for i=1:(length(X)-1 )
if ((X(i)>=4 && X(i+1)<4) || (X(i)<=4 && X(i+1)>4))
Crossings=1+Crossings;
index(i) = i;
end
end
INDEX = find(index>0);
for i = 1:(length(INDEX)-1)
a = INDEX(i);
b = INDEX(i+1);
for j = a:b
if X(j)>4
INDEX2(i,:) = [INDEX(i) INDEX(i+1)];
end
end
end
However, this code does not seem to be doing what I want it to do. It keep all the points instead of those with points above 4 inbetween. I have checked the dataset by plotting it out and I know that some of the values have values less than four between them. Where am I going wrong?

Respuestas (1)

pfb
pfb el 13 de Abr. de 2015
I'd go like
Y = X-4;
c = Y(1:(end-1)).*Y(2:end);
Now c(i) should be negative whenever X(i) and X(i+1) are "on different sides" of 4.
So, to find the crossings, all you need to do is
i = find(c<0);
I'm not sure I understand what you want, though. In your example the threshold is 4?

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by