selecting and extracting contiguous points as one event

2 ビュー (過去 30 日間)
Stephen
Stephen 2019 年 1 月 7 日
コメント済み: Stephen 2019 年 1 月 8 日
I'm sure there is probably a drop-dead simple way to do this, but my brain is fried at the moment and I can't think of one. I'm trying to identify and count numbers of events that exceed a certain value in a time series. For example, a plot of the attached file yields:Picture1.png
I'd like to be able to count the number of events that exceed the red line (y=0.13). Sometimes there is 1 point > 0.13 (e.g. the first event above at x=40) and that is easy to count as a single signal. But sometimes there are 2 or more contiguous points > 0.13 (e.g. the second event above, at x=56, 57), yet should be counted as just one "event", not as 2 events.
How can this be done? I've attached a file with the above signal.
  1 件のコメント
nanren888
nanren888 2019 年 1 月 7 日
Perhaps you could count the number of upward level-crossings?

サインインしてコメントする。

採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 1 月 7 日
let a - your data - vector.
out = sum(diff([0;a(:) > .13]) == 1);
  1 件のコメント
Stephen
Stephen 2019 年 1 月 7 日
Oh wow, GREAT! Thanks Andrei!

サインインしてコメントする。

その他の回答 (2 件)

nanren888
nanren888 2019 年 1 月 7 日
tt = linspace(0,12,1001);
s= sin(tt);
th = 0.4;
nnz(diff(s-th));
dd = [0,diff((s-th)>0)>0.5];
plot(tt,s,tt,dd);
grid('on');
nnz(dd)
ans =
2
fig.png
  1 件のコメント
Stephen
Stephen 2019 年 1 月 7 日
Thanks, nanren888! I'm having trouble applying your solution to a matrix of numbers (such as the excel spreadsheet that was attached with my Q) instead of a mathematical function such as the sin wave you show. sorry, I'm not as advanced as you are.

サインインしてコメントする。


Image Analyst
Image Analyst 2019 年 1 月 8 日
If you have the Image Processing Toolbox, the simplest way is to just use the function that was made to do exactly that: bwlabel
[~, numRegions] = bwlabel(signal > 0.13);
Can't get any easier than that.
  1 件のコメント
Stephen
Stephen 2019 年 1 月 8 日
Thanks, Image Analyst! I will investigate whether I can get the Image Processing Toolbox. In any case, the answer by Andrei Bobrov also worked well.
I appreciate this help.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTime Series Events についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by