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
Titania Markland 2018년 2월 20일
I have my data in table format. So my data was imported from an excel file.
Akira Agata
Akira Agata 2018년 2월 20일
Then, please use table2timetable function to convert it to timetable format.
Titania Markland
Titania Markland 2018년 2월 20일
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

댓글을 달려면 로그인하십시오.

답변 (2개)

Akira Agata
Akira Agata 2018년 2월 20일

0 개 추천

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 2018년 2월 20일

0 개 추천

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에 대해 자세히 알아보기

질문:

2018년 2월 19일

답변:

2018년 2월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by