Making decade time-series

1 次查看(过去 30 天)
Sarah Yun
Sarah Yun 2019-12-16
回答: dpb 2019-12-16
Hello,
I have time-series data where smallest unit of time is 1 year (i.e. the series increases in yearly increments and there is no month value.
i.e.
1978
1979
1980
1801
How should I change the code to group by the series by decades?
dt = Year; % yearly increments
% How should the next line change for only yearly increases - no months?
[groups, groupID] = findgroups(floor(year(dt)/10)*10);
% Compute decade means and ignore NAN values
decMeans = splitapply(@(x)mean(x,'omitnan'),Precip,groups);
% Display results as a table
results = table(groupID.', decMeans.','VariableNames',{'Decade','MeanTemp'});
Thank you

回答(1 个)

dpb
dpb 2019-12-16
roundyrs=fix(years(dt)/10)*10;
n=histc(roundyrs,min(roundyrs):10:max(roundyrs));
results in
>> [[min(roundyrs):10:max(roundyrs)].' n]
ans =
1800 1
1810 0
1820 0
1830 0
1840 0
1850 0
1860 0
1870 0
1880 0
1890 0
1900 0
1910 0
1920 0
1930 0
1940 0
1950 0
1960 0
1970 2
1980 1
>>

类别

Help CenterFile Exchange 中查找有关 Time Series 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by