How to sum average annual data
显示 更早的评论
Let's say I have a code from date 1/1/2004 to 31/12/2018, and I have a data of 5479x1 for each day. How do I sum the data up for each year to obtain an annual data value for each year?
= datetime(2004,01,01):calmonths(1):datetime(2018,12,31);
回答(1 个)
KSSV
2020-5-29
Convert your date time into d,m,y, using datevec. Pick a year you want, get it's indices and use mean. Let A be your data.
[y,m,d] = datevec(yourdates) ;
[c,ia,ib] = unique(y) ; % get unique years present
N = length(c) ; % Total number of years present
% loopfor each year
for i = 1:N
iwant(i) = mean(A(y==i)) ; % get mean of particular year
end
类别
在 帮助中心 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!