How to calculate monthly average for 1st, 2nd. ... 24th hour of the day?

Hello, My data are as follows (minute observations):
Date Time Temp
01/01/2011 02:03:00 6.925
01/01/2011 02:04:00 6.953333
01/01/2011 02:05:00 6.966667
01/01/2011 02:06:00 6.97
01/01/2011 02:07:00 6.986667
01/01/2011 02:08:00 6.998333
01/01/2011 02:09:00 7
01/01/2011 02:10:00 7
01/01/2011 02:11:00 7.001667
How to calculate monthly/weekly average for 1st, 2nd. ... 24th hour of the day? In other words:
Time MeanTemp(Avg/month)
1:00:00 7
2:00:00 8
Any help is appreciated! Thank you

답변 (1개)

Peter Perkins
Peter Perkins 2015년 10월 15일
In R2014b or later, assuming you have this in a CSV text file:
Date,Temp
01/01/2011 01:03:00,6.925
01/01/2011 01:04:00,6.953333
01/01/2011 01:05:00,6.966667
01/01/2011 01:06:00,6.97
01/01/2011 02:07:00,6.986667
01/01/2011 02:08:00,6.998333
01/01/2011 02:09:00,7
01/01/2011 02:10:00,7
01/01/2011 02:11:00,7.001667
Using a table and varfun, you can compute the average, by month, for each hour of the day:
>> t = readtable('tmp4.dat','Format','%{MM/dd/yyyy HH:mm:ss}D%f')
t =
Date Temp
___________________ ______
01/01/2011 01:03:00 6.925
01/01/2011 01:04:00 6.9533
01/01/2011 01:05:00 6.9667
01/01/2011 01:06:00 6.97
01/01/2011 02:07:00 6.9867
01/01/2011 02:08:00 6.9983
01/01/2011 02:09:00 7
01/01/2011 02:10:00 7
01/01/2011 02:11:00 7.0017
>> t.Month = month(t.Date);
t.Hour = hour(t.Date);
>> varfun(@mean,t,'GroupingVariable',{'Month' 'Hour'},'InputVariable','Temp')
ans =
Month Hour GroupCount mean_Temp
_____ ____ __________ _________
1_1 1 1 4 6.9537
1_2 1 2 5 6.9973
Hope this helps.

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

태그

질문:

2015년 10월 14일

댓글:

2015년 10월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by