How do I truncate a table based on a data window I'd like to use?
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Timothy
am 19 Aug. 2023
Beantwortet: Seth Furman
am 14 Sep. 2023
Hello,
I have a table with a DateTime group in the first column. It runs from midnight to midnight on a certain day. I would like to truncate the hours to between 8:00 AM and 3:00 PM, and discard all other data in the table. Is there a way to do this, or do I have to translate the date-time to something different to perform this operation? Thank you.
0 Kommentare
Akzeptierte Antwort
Voss
am 19 Aug. 2023
% I construct a table similar to yours:
TimeReceived = datetime(2023,6,26,0,0,(0:60*60*24-1).',2.6,'Format','dd-MMM-yyyy HH:mm:ss.SSSSSSSSS');
N = numel(TimeReceived);
TimeSent = 1.6878e18*ones(N,1);
RecordType = 160*ones(N,1);
T = table(TimeReceived,TimeSent,RecordType)
% keep only rows of T where TimeReceived is between 8 AM and 3 PM inclusive
tod = timeofday(T.TimeReceived);
idx = tod >= hours(8) & tod <= hours(15);
T = T(idx,:)
2 Kommentare
Weitere Antworten (1)
Seth Furman
am 14 Sep. 2023
Alternatively you can use timerange.
TimeReceived = datetime(2023,6,26,0,0,(0:60*60*24-1).',2.6,'Format','dd-MMM-yyyy HH:mm:ss.SSSSSSSSS');
N = numel(TimeReceived);
TimeSent = 1.6878e18*ones(N,1);
RecordType = 160*ones(N,1);
tt = timetable(TimeReceived,TimeSent,RecordType)
tr = timerange(datetime(2023,6,26,8,0,0),datetime(2023,6,26,15,0,0),"closed");
tt = tt(tr,:);
head(tt)
tail(tt)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!