Subset a timetable to specific time period, and only include complete data for said timeperiod

조회 수: 3 (최근 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.

답변 (1개)

Monalisa Pal
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
  댓글 수: 1
Louise Wilson
Louise Wilson 2020년 6월 22일
Hi Monalisa, yes-this works! The only thing I am unsure about in approach2 is that it should be this:
between8to5_total2 = ((h >= 8 & h <= 16) | ((h == 17) & (m == 0) & (s == 0))); % alternative to above 3 statements
%h==17, not h<=17
Do you agree? Otherwise, all times below 17 are selected, which include those times less than 8, which we don't want?
Do you have any idea how I would remove incomplete days, e.g. those where some time slots between 8-17 are missing?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by