How to take an average of three dimensional data?

Hi,
I have a three-dimensional matrix (360 x 720 x 60), in this matrix 60 represents monthly data of 5yeras (for example monthly temperature). I want to take the annual average of these monthly values so that the final matrix will be 360 x 720 x 5.

 Accepted Answer

x = your 3D matrix
result = mean(reshape(x,360,720,12,5),3);

7 Comments

Hi James,
Thank you for the reply. I used this code but it is showing error (To RESHAPE the number of elements must not change) using reshape function.
What does this show:
size(your_matrix)
x = 360 x 720 x 60;
result = mean(reshape(x,360,720,12,5),3);
it is showing error using reshape 'To RESHAPE the number of elements must not change'
I just ran the following test:
>> x = rand(360,720,60);
>> result = mean(reshape(x,360,720,12,5),3);
There is no error on my system. Please copy & paste the exact result of the following commands:
class(your_matrix)
size(your_matrix)
yes, it is working.
Thanks James.
Hi james
i have a similiar dataset but the matrix is (30x17x456) the 456 represents months i need the monthly average temperature for each month
mean(yourmatrix, [1 2])
%or
mean(reshape(yourmatrix, [], size(YourMatrix,3)))

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!