Subset a timetable to specific time period, and only include complete data for said timeperiod
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Monalisa Pal
on 22 Jun 2020
Edited: Monalisa Pal
on 22 Jun 2020
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
See Also
Categories
Find more on Tables 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!