using the find function using conditions

4 次查看(过去 30 天)
I have data for heading (varies between 0 and 360 degrees) and I want to find every point that the heading crosses 240 degrees. Attached is a picture of the heading vs time. Since we are moving in circles the pattern is repeatable. I want to find each point the heading crosses 240 degrees, but I don't want the points where the heading resets from 0 to 360 degrees denoted by the vertical line in the plot.
This is what I have in my code, but its not finding anything
find(diff(hdg) < 25 & hdg(1:end-1) < 240 & hdg(2:end) > 240)
if I remove the
diff(hdg) < 25
condition I get results but its finding the indices where the heading resets from 0 to 360 degrees (vertical line), I don't want to include those points, just where the heading actually crosses 240 degrees. Also note that the hdg data is not continuous, it looks similar to this
hdg = [0, 3.2556, 6.3458, 9.2654, 12.66, 16.225, ......237.35, 240.33, ....357.22, 1.22, ...239.55, 243.33,....]
thanks

回答(1 个)

Kirby Fears
Kirby Fears 2015-10-6
编辑:Kirby Fears 2015-10-6
Try applying abs() to the diffs - you might have the direction of your circle wrong. Also one of those hdg inequalities should be "<=" or ">=" in case you cross 240 with a value of exactly 240. Also the value of "25" could probably be larger. When a reset from 0 to 360 occurs at reasonable sampling frequency, could you guarantee a jump of 200 or more? That would ensure you don't miss any valid 240 degree crossings.
idx = find(abs(diff(hdg)) < 200 & hdg(1:end-1) < 240 & hdg(2:end) >= 240);
If this doesn't work, you should save diff(hdg) to a variable and inspect it. Maybe plot it as well.
Hope this helps.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by