MATLAB: Compute Average Matrix from Cell Array of Matrices

average matrixmultilevel array

I have a cell array of matrices of different sizes and constant length:
ABC = [(122x21) (124x21) (117x21)....]
I would like to create a new matrix, where each element contains the average of each element from each of my array matrices.
NewMat = (124x21)
where element (1,1) = mean of all of the 1,1 elements in my primary matrices element (1,2) = the mean of all of the 1,2 elements in my primary matrices
Edited to upload starting cell array

Best Answer

If you fill your missing data with zeros
a={rand(122,21), rand(124,21) , rand(117,21)} % Example
n=max(cellfun(@(x) size(x,1),a))
b=cellfun(@(x) [x ; zeros(n-size(x,1),21)],a,'un',0)
out=mean(cat(3,b{:}),3)