フィルターのクリア

Loop to check if 2 conditions are true for values 1:n, (1:n)+1, (1:n)+2, etc. in a vector and save ID

2 ビュー (過去 30 日間)
Hi everyone,
I have a time series of daily precipitation (i.e. a vector of 365x1) and I would like to test 2 conditions :
  • is the cumulative rainfall over 7 days > threshold (e.g. 10mm)
  • are there at least 4 out of 7 days with precipitation (RF > 0mm)
I want to make a loop to take values 1:7, check whether the 2 conditions above are met, go to 2:8, 3:9, etc., until the first occurrence of a 7-days period for which both conditions are met. Then save the ID of the last day of the 7-days period (e.g. if the conditions are met first for 43:49, save the ID of interest is 49, I don't care about the value in the vector, only the ID).
I have no idea how to even start or what function to use, so any help is welcome.
Thanks !
  1 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2022 年 5 月 16 日
Start with example data, just for two weeks (generate random data), it can be possible.

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

採用された回答

Torsten
Torsten 2022 年 5 月 16 日
for i=1:365-7+1
period = rainfall(i:i+6);
sum_period = sum(period);
n = numel(find(period>0));
if sum_period > threshold && n >= 4
ID = i+6;
break
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by