Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

ZERO crossing with certain conditions

1 visualizzazione (ultimi 30 giorni)
Bran
Bran il 13 Apr 2015
Chiuso: MATLAB Answer Bot il 20 Ago 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?

Risposte (1)

pfb
pfb il 13 Apr 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?

Community Treasure Hunt

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

Start Hunting!

Translated by