Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mean of rows and columns of matrices in a cell

Tags:

cell

matlab

mean

I have say n a x b matrices and I want to generate a new matrix of dimension a x b which is the mean of all n a x b matrices, i.e the first element of this new matrix is the mean of all first elements in each n a x b matrices and so on. Is there a way to compute this average matrix from a group of matrices in MATLAB? I had tried to do this by creating a cell but couldn't figure out how to take mean of each element of these matrices. I would appreciate any ideas or suggestions.

like image 920
rmb Avatar asked Dec 11 '25 20:12

rmb


1 Answers

First, put your n matrix in a single axbxn matrix

M = cat(3, mat1, mat2, mat3, ...);

Or, if you work with a cell array,

M = cat(3, cellOfMats{:})

Then just use mean along the third dimension

meanmat = mean(M,3)
like image 103
Ikaros Avatar answered Dec 13 '25 14:12

Ikaros



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!