How do I truncate a table based on a data window I'd like to use?
23 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Voss
le 19 Août 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 commentaires
Plus de réponses (1)
Seth Furman
le 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 commentaires
Voir également
Catégories
En savoir plus sur Tables dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!