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!