How to find first crossing of a threshold, then ignore n datapoints after?

50 次查看(过去 30 天)
I have a huge amount of data in a 2 column array. The first column corresponds to time, the second to a value at that time. I want to find all of the points at which the data crosses above a certain threshold. I am not interested when it comes back down across the threshold (it always does). This is also somewhat noisy data. My best solution was to find when x>4.7 (or whatever threshold), and then ignore everything for 50 seconds, then repeat (there should be 5 times when there's an ascending threshold cross). Unfortunately I can't get this to work...unsure of how to store these times when there is an ascending threshold cross and also can't seem to figure out a way to ignore for 50s. Any ideas?

回答(2 个)

Siddharth Sundar
Siddharth Sundar 2014-10-29
If I understand correctly, you just want to be able to find the indices where your values in a vector cross a certain threshold in the positive direction while excluding the values where the threshold is crossed while moving in the negative direction.
Here is some commented script that does exactly that:
thresh = 1.7; % Specify threshold
x = [1.8 1.3 1.6 1.7 1.2 1.2 1.7 1.8 1.7 1.8 2 2.3 4.1 3 1.2 1.4 1.7 2.1];
% Essentially need to pick out values which exceed threshold with the condition that the previous value
% needs to be below the threshold
idxl = x>=thresh;
idxl(1) = 0;
idx = find(idxl);
yest = x(idx-1)<thresh;
idx(yest) % Final output
  1 个评论
krishna kireeti
krishna kireeti 2017-3-7
Dear sir, I had a huge data in matrix form and I want to know how many times does the data between a given period crossed the threshold value, can you help with the code?

请先登录,再进行评论。


simith
simith 2017-9-1
please how to write a code to check number of up crossing and down crossing for a level in matlab

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by