Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

ZERO crossing with certain conditions

1 vue (au cours des 30 derniers jours)
Bran
Bran le 13 Avr 2015
Clôturé : MATLAB Answer Bot le 20 Août 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?

Réponses (1)

pfb
pfb le 13 Avr 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?

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by