How to find all datetimes that are within predefined time windows (plural!)?
Show older comments
Hi!
I have a table T with integers in the first column and datetimes in the second column and a cell-array TW of tables with 2 columns TW.start and TW.end datetimes of N rows/timewindows (N varies).
Now I want to find all datetimes in T that are within the time windows.
I know the command isbetween(t,tlower,tupper):
for ii=1:size(TW,1)
T(:,ii+1) = isbetween(T.Times,TW{ii}.start,TW{ii}.end)
end
This produces the error:
Error using datetime/isbetween>isbetweenUtil (line 91)
All inputs must have a common size, or be scalar.
I guess it is not possible to use isbetween with arrays (of same size) as tlower and tupper.
Is there an alternative direct function to solve my problem?
I mean, i could work around with a nested loop... or create new arrays with all minutewise datetimes between start and end and use ismember... But there must be a better way, which I don't know or can't think of at the moment.
Thanks in advance!
6 Comments
What are the heights of the table T and the tables stored in the cells of TW?
If those heights aren't all the same, what would you want to do in this case?
Tdates = datetime('today') + days([0; 1; 2])
TWdates = datetime('today') + days([-5 -4; -3 1; 5 6; -2 1.5])
The first element of Tdates is in the range specified by the second and fourth rows of TWdates but none of the others. Does it need to be in the range specified by the first row of TWdates to be counted in or can it be in the range of any of the rows to count?
The third element of Tdates is outside of any of those intervals, but is between the first and last dates in TWdates. Does that make it in or out?
What if anything should be done with the fourth row of TWdates?
KSSV
on 24 Jun 2021
Why you want to use a function? You can use inequalities.
Sebastian
on 24 Jun 2021
KSSV
on 24 Jun 2021
You already got it....
Answers (0)
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!