Subset a timetable to specific time period, and only include complete data for said timeperiod
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a timetable which contains a list of filenames and a count containing information about the file:
DateTime Filename Count
'10-Jun-2019 16:02:00' 'GoatIsland-20190610-1602-0001.png' 0
'10-Jun-2019 16:12:00' 'GoatIsland-20190610-1612-0002.png' 0
'10-Jun-2019 16:22:00' 'GoatIsland-20190610-1622-0003.png' 0
The datetimes could occur at any time throughout the day but I want to reduce them to those that occur after 0800 up until 1700 only, including 1700 itself. I have figured out how to get it up to 1659 by subsetting on the hour:
row_hours=hour(boatcounts.DateTime); %identify hours within datetime
between8to5=ismember(row_hours, [8:16]); %select hours of interest
boatcountsTT_daily=boatcountsTT(between8to5,:); %subset
but what I really want is to include the values at 1700 too, something like:
between8to5=ismember(row_hours, [>=8 && <=17]); %select hours of interest
...how could I make this change? I've tried a few different ways but none are syntactially correct.
Furthermore, I have complete datasets for most of the days, i.e. data runs from 8 to 5pm, but sometimes there are short days where a few times are missed either at the start, middle or end of the day. How could I limit the data to include only those days which a full dataset, where the time steps in 10 minutes every day from 8 to 5pm?
Thanks for your help.
댓글 수: 0
답변 (1개)
Monalisa Pal
2020년 6월 22일
편집: Monalisa Pal
2020년 6월 22일
How about these options?
%% your solution
row_hours=hour(boatcounts.DateTime); %identify hours within datetime
between8to5=ismember(row_hours, 8:16); %select hours of interest
boatcountsTT_daily=boatcounts(between8to5,:); %subset
%% new solutions
[h,m,s]=hms(boatcounts.DateTime); %identify hours within datetime
between8to5_new=ismember(h, 8:16); %select hours range [08:00:00, 16:59:59]
at5=((h == 17) & (m == 0) & (s == 0)); %select hour 17:00:00
between8to5_total1 = or(between8to5_new, at5); %combine to range [08:00:00,17:00:00]
between8to5_total2 = ((h >= 8 & h <= 16) | ((h <= 17) & (m == 0) & (s == 0))); % alternative to above 3 statements
boatcountsTT_daily_new1=boatcounts(between8to5_total1,:); %approach1
boatcountsTT_daily_new2=boatcounts(between8to5_total2,:); %approach2
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!