How do I truncate a table based on a data window I'd like to use?
조회 수: 24 (최근 30일)
이전 댓글 표시
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
채택된 답변
Voss
2023년 8월 19일
% 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,:)
추가 답변 (1개)
Seth Furman
2023년 9월 14일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!