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 commentaires

Titania Markland
Titania Markland le 20 Fév 2018
I have my data in table format. So my data was imported from an excel file.
Akira Agata
Akira Agata le 20 Fév 2018
Then, please use table2timetable function to convert it to timetable format.
Titania Markland
Titania Markland le 20 Fév 2018
My data is in half hourly recordings, so I used the following code to convert to daily: t=reshape(t,48,[]); mean (t);
But after this part I think I am confused as what to do next to get it to monthly average?
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

Connectez-vous pour commenter.

Réponses (2)

Akira Agata
Akira Agata le 20 Fév 2018
If your data is stored in timetable format, you can do that simply using retime function, like:
newTimeTable = retime(yourTimeTable,'monthly','mean');
Andrei Bobrov
Andrei Bobrov le 20 Fév 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');

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by