フィルターのクリア

Round Datetime to certain minutes

9 ビュー (過去 30 日間)
Dario Walter
Dario Walter 2020 年 11 月 19 日
コメント済み: Dario Walter 2020 年 11 月 20 日
Hey,
I am trying to round an array of datatype datetime to nearest 20 and 50 minutes, e.g. 16:30 - 16:20, 16:54 - 16:50, 16:01 - 15:50, 2020Nov19 00:01 - 2020Nov18 23:50. Does anyone have an idea? I already tried dateshift and interp1.
Your help is highly appreciated.

採用された回答

dpb
dpb 2020 年 11 月 19 日
interp1 will work...
dt=datetime(2020,11,18,00,1+[0:30].',0); % sample datetime array
dt20=datetime(2020,11,17,0,[20:30:2400].',0); % 30 min array at 20, 50 past hour
>> interp1(dt20,dt20,dt,'nearest')
ans =
31×1 datetime array
17-Nov-2020 23:50:00
17-Nov-2020 23:50:00
17-Nov-2020 23:50:00
17-Nov-2020 23:50:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
18-Nov-2020 00:20:00
>>
There's probably more clever ways...
  1 件のコメント
Dario Walter
Dario Walter 2020 年 11 月 20 日
So close but yet so far. Thank you!

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by