Half hour data to monthly average
显示 更早的评论
How do I calculate monthly average from daily half hour readings? Is there a specific function that can do this?
4 个评论
Titania Markland
2018-2-20
Akira Agata
2018-2-20
Titania Markland
2018-2-20
Akira Agata
2018-2-20
OK. Looking at your code, I think your data is stored in the N-by-1 numeric array. Then, I would recommend making a time stamp (N-by-1 datetime array), and convert them to timetable format.
The following sample code shows how to create time stamp (N-by-1 half-hourly datetime array), combine with data to make timetable, and calculate monthly average.
% Time stamp
Time = (datetime(2018,1,1):minutes(30):datetime(2019,1,1)-minutes(30))';
% Sample data
Data = 10+rand(numel(Time),1);
% Store the data as a timetable
TT = timetable(Time,Data);
% Calculate monthly average
TT2 = retime(TT,'monthly','mean');
The TT and TT2 looks like:
>> TT(1:4,:)
ans =
4×1 timetable
Time Data
__________ ______
2018/01/01 10.06
2018/01/01 10.682
2018/01/01 10.042
2018/01/01 10.071
>> TT2(1:4,:)
ans =
4×1 timetable
Time Data
__________ ______
2018/01/01 10.498
2018/02/01 10.509
2018/03/01 10.508
2018/04/01 10.491
回答(2 个)
Akira Agata
2018-2-20
newTimeTable = retime(yourTimeTable,'monthly','mean');
Andrei Bobrov
2018-2-20
d = 10*rand(275,48) - 5;% let d - your data -> one row - one day
date1 = datetime(2018,2,20 + (0:size(d,1)-1)') ; % Enter date of first day, e.g. - 20-Feb-2018
TT = array2timetable(mean(d,2),'RowTimes',date1);
% Further, as Akira wrote:
TTout = retime(TT,'monthly','mean');
类别
在 帮助中心 和 File Exchange 中查找有关 Timetables 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!