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

조회 수: 1 (최근 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 CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by