SONY
SONY

Reputation: 33

How to calculate yearly values from monthly data in three dimensional matrix?

I have monthly rainfall data in three dimensional matrix and I want to calculate total annual rainfall from monthly rainfall data. Three dimensional data (180 x 360 x 120), where 180 x 360 is 1 degree by 1 degree grids and 120 is number of months (for 10 years).

Now I want to covert monthly values into years by summing the monthly values of each year (12*10=120) so that after summing my final output will be 180 x 360 x 10. How would I do this in matlab?

Upvotes: 0

Views: 305

Answers (1)

souty
souty

Reputation: 607

Try this:

% create sample data
tt = rand(180,360,120);

% aggregate monthly data to yearly
ttt = reshape(tt,180,360,12,[]);    % reshape to separate individual months
ttt = sum(ttt,3);                   % sum over years
ttt = squeeze(ttt);                 % squueze 4D array into 3D array

Hope this helps.

Upvotes: 1

Related Questions