search interval in datetime
3 ビュー (過去 30 日間)
古いコメントを表示
hi, I have a datetime array of several many days. I need to serch interval
example:
TimeA=22:00
TimeB=03:00
search datetime>=timeA and datetime<=timeB (22:00 ..22:01..22:02. etc......23:59 ..00:00...00:01.etc... 2:58..2:59 3:00)
So I want without checking the day to have the indices of that range in the whole array
(the times in datetime are already ordered in a correct chronological way so the next time is always after the previous one)
0 件のコメント
採用された回答
Steven Lord
2024 年 5 月 21 日
T = datetime('today') + hours(24*rand(10, 1))
TOD = timeofday(T)
Then compare to duration objects representing the ends of the interval of interest. In this case because the interval includes midnight we need to ask if the timeofday is greater than the first end or less than the second end.
past2200 = TOD > duration(22, 0, 0)
before0300 = TOD < duration(3, 0, 0)
T(past2200 | before0300)
results = table(T, past2200, before0300, past2200 | before0300, ...
'VariableNames', ["times", "> 2200", "< 0300", "overnight"])
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Calendar についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!