hourly average of data from 30mins past the hour

조회 수: 1 (최근 30일)
Maitiumc
Maitiumc 2016년 12월 2일
편집: Maitiumc 2017년 3월 20일
I'm working on some solar irradiance data, I have been able to get the hourly average using the following code:
DateNumber = timeStamp(:,1);
formatOut = 'dd mm yyyy HH:MM:SS';
str = datestr(DateNumber,formatOut);
%Creates coloum vectors corresponding to month, day and hour
%these are used to find the hourly average for each day of the month
%averages for irradiance, temperature and wind speed are calculated
Cell = cellstr(str);
[~,Mth,Day,Hr] = datevec(Cell, 'dd mm yyyy HH:MM:SS');
subs = [Mth Day Hr+1];
hrly_mean_ir = accumarray(subs, I,[], @mean); % hourly mean irradiance
hrly_mean_ws = accumarray(subs, Ws,[], @mean);
hrly_mean_temp = accumarray(subs, T, [], @mean);
The problem with this is when I plot it, for example the data for each day should peak around 12pm. But since the average for 1100 to 1200 (or 1200 to 1300 depending on the plot) the peak can be shifted slightly off the midday point.
What I need is the hour to 'start' at 30mins past the hour, eg for 12pm the average would be 1130 to 1230
I'm not too sure how I can get the hourly average in this format however.

답변 (1개)

Alexandra Harkai
Alexandra Harkai 2016년 12월 2일
You could avoid the date conversion back-and-forth business by sticking to DateNumber. Getting not only the hours but the minutes for those DateNumber values you can add an hour only on the ones where the minutes indicate they are at least 30mins past the hour, pushing them to the next 'bucket'.
DateNumber = timeStamp(:,1);
%Creates coloum vectors corresponding to month, day and hour
%these are used to find the hourly average for each day of the month
%averages for irradiance, temperature and wind speed are calculated
[~,Mth,Day,Hr,Mn] = datevec(DateNumber);
subs = [Mth Day Hr+Mn>=30];
hrly_mean_ir = accumarray(subs, I,[], @mean); % hourly mean irradiance
hrly_mean_ws = accumarray(subs, Ws,[], @mean);
hrly_mean_temp = accumarray(subs, T, [], @mean);
  댓글 수: 1
Maitiumc
Maitiumc 2017년 3월 20일
편집: Maitiumc 2017년 3월 20일
Sorry for the late response!
Running this will give me:
Error using accumarray
First input SUBS must contain positive integer subscripts.
Error in filename (line 46)
hrly_mean_ir = accumarray(subs, I,[], @mean);
And also looking at the hour values in subs, they seems to be either 1 or 0, not 1 through to 24

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

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by