I have a climatic dataset of a region where I am calculating time series (for drought index). The dimension of the dataset is 164*153*1416 (1416 months in the dataset and the others are the location). How I can average this over space and time?

 Accepted Answer

To get a map of average SPEI,
SPEI_mean = mean(SPEI,3,'omitnan');
and that calculates the mean along the third dimension (time).

4 Comments

Hi Chad! Thanks. But I am still stucked as, when I average it along the third dimension, it converts into 164*153 (two dimension). I want to extract/plot the time series for average SPEI. In the dataset, the dimension of time is 1*1416. How I can do that as the length is different for average average SPEI and time?
By default, the mean function calculates the mean across the first nonsingleton dimension. So if you calculate
SPEI_mean = mean(SPEI,'omitnan');
the result will be 1x153x1416, because it's taken the mean along the first dimension. If you take the mean of the mean like this:
SPEI_mean = mean(mean(SPEI,'omitnan'),'omitnan');
then the answer will be 1x1x1416. That's the time series you want, but you'll probably want to squeeze it like this:
SPEI_mean = squeeze(mean(mean(SPEI,'omitnan'),'omitnan'));
which turns it into a 1416x1 vector that you can plot via
plot(t,SPEI_mean)
If you want to calculate the mean within a specific region rather than the entire dataset, like the mean SPEI within the boundaries of a desert or something, try the local function in the Climate Data Toolbox.
It works @Chad Greene. Thanks a lot. The cdt is really helpful and a great piece of good work.
@Chad Greene, If i have a dataset (360*720*1416) where first two indicate latitude and longitude and 1416 is the time step. If I need finer resolution (0.25 degree spatial resolution) to make it (720*1440*1416), how I can do that?

Sign in to comment.

More Answers (0)

Categories

Find more on Climate Science and Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!