How to filter rows in a timetable based on a range between 08:00 and 16:00 for everyday and put in a new timetable

47 visualizzazioni (ultimi 30 giorni)
Hi, I need to filter som data I have so that I get the rows from only the time between 08:00 and 16:00 or the "occupied time" where I am assuming there will be people present in my measurements. The data I have is a date in column 1 and in 2,3,4 I have temperature, relative humidity and CO2. But the data I have now is for all 24 hours of everday in about a month of data.
How can I filter this data and put it in its own timetable since I want to plot both the whole measuring period and also the isolated range.
I can use the rangetime function like this:
S = timerange(' 21-Oct-2019 08:00:00',' 21-Oct-2019 17:00:00'); %Creating a variable S with the values within the timerange.
TT2 = IC11avHour(S,:); %Creating the new timetable with the rows of information.
And then TT2 is my new timetable and this works but this is only for 1 day but I want it for all days within the timerange.
Can anyone help me?

Risposte (1)

Eric Sofen
Eric Sofen il 4 Dic 2019
You can do this with some logical indexing on the row times.
Create a timetable with a few days worth of hourly data:
tt = timetable((1:100)','TimeStep',hours(1),'StartTime',datetime)
The hour() function gives the clock hour of a datetime, so get all times between 08:00 and 17:00
tt(hour(tt.Time)<=17 & hour(tt.Time)>=8,:)
ans =
44×1 timetable
Time Var1
____________________ ____
04-Dec-2019 11:41:07 1
04-Dec-2019 12:41:07 2
04-Dec-2019 13:41:07 3
04-Dec-2019 14:41:07 4
04-Dec-2019 15:41:07 5
04-Dec-2019 16:41:07 6
04-Dec-2019 17:41:07 7
05-Dec-2019 08:41:07 22
05-Dec-2019 09:41:07 23


Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by