how to determine if vector of row times is within timerange?

2 ビュー (過去 30 日間)
clauper
clauper 2023 年 1 月 24 日
編集済み: Stephen23 2023 年 1 月 24 日
I have a vector of row times and a time range:
dates = datetime(2000,1,1):calyears(1):datetime(2002,1,1);
tr = timerange(datetime(2000,1,1), datetime(2001,12,31));
and I would like to determine whether "dates" is within the timerange, such that i get
answer = [true;true;false]
answer = 4×1 logical array
1 1 0 0
Is there a function or approach that does this?
  1 件のコメント
Stephen23
Stephen23 2023 年 1 月 24 日
編集済み: Stephen23 2023 年 1 月 24 日
Note that using datetime(2001,12,31) as the bin edge will miss any times that fall during the 31st of December:
isbetween(datetime(2001,12,31,12,35,45), datetime(2000,1,1), datetime(2001,12,31))
ans = logical
0

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

採用された回答

Rik
Rik 2023 年 1 月 24 日
The timerange datatype is really only intended to be used with timetables. Once you convert your dates to a timetable, you can use the containsrange function:
dates = datetime(2000,1,1):calyears(1):datetime(2002,1,1);
tr = timerange(datetime(2000,1,1), datetime(2001,12,31));
tmp = timetable(reshape(dates,[],1),ones(numel(dates),1));
[tf,whichRows] = containsrange(tmp,tr)
tf = logical
1
whichRows = 3×1 logical array
1 1 0

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by