Average specific times across a range of dates
3 views (last 30 days)
Show older comments
I have a large dataset of "minutely" data that has been "cleaned" (there are no duplicates, smaller dt's, or missing minute data)
I have isloated 6 days worth of it in a matlab TimeTable, and want to average together the values at each minute time interval regarless of the day.
So for example if I have:
'6-22-2015 15:04', 5
'6-22-2015 15:05', 2
'6-22-2015 15:06', 3
...
'6-23-2015 15:04', 10
'6-23-2015 15:05', 5
'6-23-2015 15:06', 6
...
'6-24-2015 15:04', 0
'6-24-2015 15:05', 5
'6-24-2015 15:06', 9
I would like it to show:
'15:04', 5
'15:05', 4
'15:06', 6
...
Can Timetables have time values with no associated dates? Should I try and shift the data to all be on the same day?
0 Comments
Answers (1)
Chunru
on 11 May 2021
% Create the data cell array
x ={
'6-22-2015 15:04', 5
'6-22-2015 15:05', 2
'6-22-2015 15:06', 3
'6-23-2015 15:04', 10
'6-23-2015 15:05', 5
'6-23-2015 15:06', 6
'6-24-2015 15:04', 0
'6-24-2015 15:05', 5
'6-24-2015 15:06', 9};
% Convert it into a time table
t = datetime(x(:,1), 'InputFormat', 'mm-dd-yyyy HH:mm');
v = cell2mat(x(:, 2));
tt =timetable(t, v);
% For example, find the data has same hour and minute as '15:04'
str = '15:04'
idx = minute(tt.t) == minute(str) & hour(tt.t) == hour(str)
av = mean(tt.v(idx));
% The result:
str, av
0 Comments
See Also
Categories
Find more on Dates and Time 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!