Half hour data to monthly average
Show older comments
How do I calculate monthly average from daily half hour readings? Is there a specific function that can do this?
4 Comments
Titania Markland
on 20 Feb 2018
Akira Agata
on 20 Feb 2018
Titania Markland
on 20 Feb 2018
Akira Agata
on 20 Feb 2018
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
Answers (2)
Akira Agata
on 20 Feb 2018
newTimeTable = retime(yourTimeTable,'monthly','mean');
Andrei Bobrov
on 20 Feb 2018
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');
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!