How to get monthly averages from daily data?

조회 수: 6 (최근 30일)
Muhammad shahid
Muhammad shahid 2017년 11월 23일
댓글: Muhammad shahid 2017년 11월 23일
Hello,
I have an excel file containing 4 column. The first column contain year month day (YEARMODA), the second column contain daily Maximum Temperature (MAX T), the third column contain daily Minimum Temperature (MIN T) and fourth column contain Precipitation data (PRCP). In first column there are missing days for every month its hard to find them one by one. I need monthly average values of MAX T, MIN T and PRCP. The given and required form of data is attached.

채택된 답변

KSSV
KSSV 2017년 11월 23일
편집: KSSV 2017년 11월 23일
[num,txt,raw] = xlsread('A.xls') ;
date = datevec(num2str(num(:,1)),'yyyymmdd') ;
years = date(:,1) ;
months = date(:,2) ;
%%Get average
[Y,ia,ib] = unique(years) ;
[M,ia,ib] = unique(months) ;
iwant1 = zeros(length(Y),length(M)) ; % Average of max T
iwant2 = zeros(length(Y),length(M)) ; % Average of min T
iwant3 = zeros(length(Y),length(M)) ; % Average of PRCP
for i = 1:length(Y)
idx_Y = years==Y(i) ;
data = num(idx_Y,2:end) ;
YM = months(idx_Y) ;
for j = 1:length(M)
idx_M = YM==M(j) ;
iwant1(i,j) = mean(data(idx_M,1)) ;
iwant2(i,j) = mean(data(idx_M,2)) ;
iwant3(i,j) = mean(data(idx_M,3)) ;
end
end
  댓글 수: 3
KSSV
KSSV 2017년 11월 23일
Edited the answer...
Muhammad shahid
Muhammad shahid 2017년 11월 23일
Dear KSSV
Bundle of thanks for guidance and spending your time to solve this issue. The provided matlab code worked for me and it saved my time. This code will be very valuable for hydrologists. I will recommend this code if some one is using GHCN precipitation and temperature data for analysis.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Weather and Atmospheric Science에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!