I have a cell array called template, where template is a 1x29 cell array. Each cell of template is a 14x10x31 matrix. Each element of the matrix is a double.
I want to find the mean 14x10x31 matrix of template i.e. I want a result which is a 14x10x31 matrix where e.g. element (1,1,1) of the result is the mean of all 29 values of (1,1,1) in the cell array template.
I'm not clear how to go about this.
I've looked at cellfun
, and the options for the mean
command i.e. how mean can be calculated across dimensions. For example, to calculate mean m across all three dimensions would be done as follows ...
m = cellfun(@(x) mean(mean(mean(x,1),2),3) , template, 'UniformOutput', false)
... which will give 1x29 cell array, each cell containing a single value i.e. the averaging together of all values in each 14x10x31 array, for each cell of the template variable.
But obviously this isn't what I want.
To achieve what I want do I need to convert (cell2mat
?) the template variable to a matrix of 29x14x10x31 and then run mean
on the first dimension of that? I've looked at reshape
and cat
too but I'm not clear how to put it all together though ... or if that is the best way to achieve what I want? Or can it / should it be done by using cellfun
?