MATLAB: Finding mean for an array

cell arrays

Hi all, Just wanted to find mean for an array thnx

Best Answer

For numeric arrays:
mean(NumericArrayName(:))
I see, though, that you tagged this with "cell arrays". If you are wanting to find the mean for each cell separately, then:
cellfun(@(C) mean(C(:)), CellArrayName)
If you are wanting to find the mean of all of the cells taken together as if they were one long list of numbers:
t = cellfun(@(C) C(:), CellArrayName);
mean(vertcat(t{:}))
I am presuming in the above that when you say that you want to find the mean for an array, that you want the mean of all of the numbers in the array together. If you want the mean of the rows of an arithmetic array, then mean(NumericArrayName,2) and if you want the mean of the columns then mean(NumericArrayName)
But if what you have is a cell array containing a series of numeric arrays all the same size, and you want a position-by-position mean over all of the cells, then:
nd = ndims(CellArrayName{1});
mean(cat(nd, CellArrayName{:}), nd)