Calculating mean values of a 3D matrix for every rows

I have a matrix 12x441x1440. 12 is the dimension of time. how can I get 12 average numbers for every month from that matrix

 Akzeptierte Antwort

Simon Chan
Simon Chan am 30 Mär. 2022
Try this:
mean(yourmatrix,[2 3]);

4 Kommentare

comes an error like this
Error using sum
Dimension argument must be a positive integer scalar within indexing range.
Error in mean (line 117)
y = sum(x, dim, flag)/size(x,dim);
What is the dimension of your matrix?
Could you do size(yourmatrix)?
A = rand(12,441,1440);
size(A)
ans = 1×3
12 441 1440
B = mean(A,[2 3])
B = 12×1
0.4996 0.5005 0.4993 0.5002 0.4999 0.4999 0.5005 0.5002 0.5006 0.4996
Look like you have old MATLAB version
mean(mean(yourmatrix,2),3);
thanks Bruno

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by