MATLAB: By element average of multiple matrices

elementmatricesmeanmultipeof

Hi,
I have 40 matrices of 781×981 in dimension. I need to calculate the by element mean of all these matrices in a new, 41st matrix.
I.e., the mean of element 1,1 of all 40 matrices is returned as element 1,1 in the new, 41st matrix. The same is then done for all elements.
In additionto the mean, I need to do the same for the standard deviation also.
Is there a function in Matlab that can do this? Or do I have to write some kind of a loop??
Thanks, Bryan

Best Answer

Yes, concatenate the matrices into a 3-D array and use mean(x,3)
x = randn(4,4,10);
mean(x,3)
and
std(x,[],3)
To concatenate, you can use cat()
x = randn(4,4);
y = randn(4,4);
z = cat(3,x,y);
mean(z,3)
std(z,[],3)