Filter löschen
Filter löschen

Find timeseries mean for 10 years

2 Ansichten (letzte 30 Tage)
Sarah Yun
Sarah Yun am 15 Dez. 2019
Kommentiert: Adam Danz am 16 Dez. 2019
Hi,
I have time-series temperature data for years 1950 to 2010.
I want to calculate the decadal means i.e. 1950 - 1960, 1960 - 1970 etc and plot them as a histogram
What code should I use to calculate the 10 year means?
Thank you.

Akzeptierte Antwort

Adam Danz
Adam Danz am 15 Dez. 2019
Bearbeitet: Adam Danz am 15 Dez. 2019
Assuming you have a vector named temperature that stores the temperatures and a vector named dt that stores the datetime stamps (in datetime format), you can use findgroups() to group the data into decades and then splitapply() to calculate the group means.
% Create demo data
dt = datetime(1950,1,1):datetime(2019,12,15);
temperature = rand(size(dt)) * 100;
% Group by decade
[groups, groupID] = findgroups(floor(year(dt)/10)*10);
% Compute decade means
decMeans = splitapply(@mean,temperature,groups);
% Put results into a table
results = table(groupID.', decMeans.','VariableNames',{'Decade','MeanTemp'});
View results
results =
7×2 table
Decade MeanTemp
______ ________
1950 49.348
1960 50.959
1970 50.13
1980 49.847
1990 49.808
2000 49.471
2010 49.404
[update]
If there are NaN values you'd like to ignore,
decMeans = splitapply(@(x)mean(x,'omitnan'),temperature,groups);
  6 Kommentare
Sarah Yun
Sarah Yun am 16 Dez. 2019
Thank you.
How do I find the p-values?
It shows a box-plot only.
Adam Danz
Adam Danz am 16 Dez. 2019
Did you look at the p output?
Here's more info

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Identification finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by