필터 지우기
필터 지우기

Average specific times across a range of dates

조회 수: 3 (최근 30일)
Mike I.
Mike I. 2021년 5월 11일
답변: Chunru 2021년 5월 11일
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?

답변 (1개)

Chunru
Chunru 2021년 5월 11일
% 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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by