MATLAB Answers

How to do if statement for a specific value that lasts for more than 2 seconds

1 ビュー (過去 30 日間)
Saad Alqahtani
Saad Alqahtani 2021 年 7 月 9 日
コメント済み: Saad Alqahtani 2021 年 7 月 9 日
Hi,
I'm trying to see if a specific value exists for more than 2 seconds.
here is my code:
isOK2 = (Discard2_to_end <=Discard2value); % logical array
t = 2*fsamp; % 2 seconds interval
I want to use if statement if 1 exists for more than 2 seconds.
Any help would be appreciated. Thanks in advance.

採用された回答

Walter Roberson
Walter Roberson 2021 年 7 月 9 日
isOK2 = reshape(isOK2, 1, []); %need row vector
starts = strfind([0, isOK2], [0 1]);
stops = strfind([isOK2, 0], [1 0]);
burst_duration = stops - starts + 1;
burst_is_long_enough = burst_duration >= t;
starts = starts(burst_is_long_enough);
stops = stops(burst_is_long_enough);
starts and stops will now be vectors of starting and ending indices of places with bursts that were long enough. They will be empty if there were no sufficiently long bursts.
  1 件のコメント
Saad Alqahtani
Saad Alqahtani 2021 年 7 月 9 日
That helps. Thank you so much!

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

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by