How can I select data of an specific hour of each day on a time series sampled every 5 minutes ?

6 views (last 30 days)
I have my data in a table and separated in two columns. The first colum is a datetime column that contains the date and the time of each day of a year for data sampled every 5 minutes (f example: 01-Jan-2014 00:05:00 , 01-Jan-2014 00:10:00 ... 31-Dec-2014 23:55:00) and in the second column I have my Temperature data. With the groupsummary function I have managed to calculate hourly, daily, monthly and yearly means specifying "hour", "day" or "month" on the input arguments but now, I would like to know if I can choose with this function (or with any other) the data of an specific hour of each day, for example, the temperature data of each day at 2:00 am to compare it with the data of a satelite obtaining the 365 temperature values of every single day at 2:00 am of the year.
Thanks for your time.
  2 Comments
Siddharth Bhutiya
Siddharth Bhutiya on 5 Apr 2022
I dont see a way to do this directly, but you can use subscripting to get the desired subset and then use groupsummary on the subset timetable
>> head(tt)
dt Temp
____________________ ________
01-Jan-2014 00:00:00 0.21896
01-Jan-2014 01:00:00 0.047045
01-Jan-2014 02:00:00 0.67886
01-Jan-2014 03:00:00 0.6793
01-Jan-2014 04:00:00 0.93469
01-Jan-2014 05:00:00 0.3835
01-Jan-2014 06:00:00 0.51942
01-Jan-2014 07:00:00 0.83097
>> tt2am = tt(hour(tt.dt) == 2,:);
>> head(tt2am)
dt Temp
____________________ _______
01-Jan-2014 02:00:00 0.67886
02-Jan-2014 02:00:00 0.7622
03-Jan-2014 02:00:00 0.16651
04-Jan-2014 02:00:00 0.7702
05-Jan-2014 02:00:00 0.17833
06-Jan-2014 02:00:00 0.23991
07-Jan-2014 02:00:00 0.9611
08-Jan-2014 02:00:00 0.36534
>> groupsummary(tt2am,'Temp')
ans =
365×2 table
Temp GroupCount
_________ __________
0.0004036 1
0.0016643 1
0.012213 1
0.015499 1
0.018916 1
0.022251 1
0.022677 1
0.026834 1
0.03004 1
0.030504 1
Victor Martinez
Victor Martinez on 6 Apr 2022
Thank you for your help Siddarth, it worked perfectly !
Actually with your code I got all the temperature values of each day between 2:00:00 am to 2:55:00 but I applied again the same code to the new variable tt2am specifying now minutes equal to zero (tt2am = tt2am(minute(tt2am.dt) == 0,:) and I have now a table with the temperature data of each day at 2:00 am exactly which is just what I was looking for.

Sign in to comment.

Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!