Azzera filtri
Azzera filtri

mean seasonal data

4 visualizzazioni (ultimi 30 giorni)
niclo
niclo il 23 Feb 2012
Commentato: Robert il 23 Mag 2018
Hello,everyone. I have a seasonal data set which is 123 x 21 x 23 double. the data is arrange in this way :1st is dec 1959, second is jan 1960, third is feb 1960,forth is dec 1960, fifth is jan 1961 and until feb 2000. I need to mean the DJF of every year so that i will have only 1 value for each year. At the end, i will want to hv only 1 row which the 1st is mean value of DJF1960, 2nd is mean value of DJF1961. Can anyone help me to solve this problem? Thank you.
if I had to do this manualy it probably look like this:
a(1,:)=mean(mean(unnamed(1:3)));
b(1,:)=mean(mean(unnamed(4:6))); . .
n(1,:)=mean(mean(unnamed(120:123)));
all=[a;b;c.....n];
But Of cousre I cannot do it manually because it will probably take the rest of my life! and i have many other set of data. So how can I replicate this for a huge dataset? Can anyone teach me how to write a loop so that i don't have to repeat my work until 123 times?
  2 Commenti
Oleg Komarov
Oleg Komarov il 23 Feb 2012
It's not clear how your data is organized.
row 1-3 = data for Dec 1960 - Feb 1961 and so on
What's in column 1,2 etc
And why fo you have 23 layers (3rd dimension)?
niclo
niclo il 24 Feb 2012
My data is arranged in this way:
dec 1959
jan 1960
feb 1960
mar 1960
apr 1960
may 1960
jun 1960
jul 1960
aug 1960
sep 1960
oct 1960
nov 1960
dec 1960
jan 1961
.
.nov 2000
So i would like to extract the DJF for every year, so that my data will become like this:
dec 1959
jan 1960
feb 1960
dec 1960
jan 1961
feb 1961
..
After that, i need to mean the DJF for every year. So at the end my data will become 1 x 41 (because i have 41 years).
My original data is 123 x 21 x 23, the 21 is latitude and 23 is longitude.

Accedi per commentare.

Risposta accettata

Bjorn Gustavsson
Bjorn Gustavsson il 23 Feb 2012
QD:
idxDJF = sort([[1:12:123],[2:12:123],[3:12:123]]);
Wacc = cumsum(unnamed(idxDJF,:,:));
Wavg = Wacc(3:3:end,:,:)/3;
Will leave you with a Wavg with size: 11 x 21 x 23.
HTH

Più risposte (1)

Danhay
Danhay il 22 Feb 2016
I am answering this in case someone else is having a similar problem. I have a matlab script to handle this problem for both 2D and 3D data: http://dans7messiah.thoughts.com/posts/calculating-the-mean-for-a-selected-period-to-create-a-time-series-of-mean-matlab
Cheers, Daniel
  3 Commenti
saida ghrab
saida ghrab il 18 Mag 2017
Hello Danhay, I have the same problem but I couldn't download the script can you please check the link. Thank you so much
Robert
Robert il 23 Mag 2018
Hi Danhay, would be possible to have the latest link to your script? Links provided are not working.

Accedi per commentare.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by