Info

此问题已关闭。 请重新打开它进行编辑或回答。

ZERO crossing with certain conditions

1 次查看(过去 30 天)
Bran
Bran 2015-4-13
关闭: MATLAB Answer Bot 2021-8-20
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?

回答(1 个)

pfb
pfb 2015-4-13
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