cellfun operates on the contents of each cell independently, performing the specified function (in this case the function is mean(x,1)). If the outputs of those function calls are all scalars of the same class, then cellfun is able to combine all the results into an array (which it will do by default). Otherwise, you need to use 'UniformOutput',false to have cellfun return a cell array.
Examples:
result = cellfun(@(x)x,C1)
end
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.
C2 = {single(1) double(2)}
result = cellfun(@(x)x,C2)
end
Mismatch in type of outputs, at index 2, output 1 (single versus double).
Set 'UniformOutput' to false.
In both of those examples, you must use 'UniformOutput',false to have cellfun return a cell array instead of trying to construct a numeric matrix and erroring-out. Of couse, since the function is @(x)x, the resulting cell array from cellfun will be the same as what you gave it.
result = cellfun(@(x)x,C1,'UniformOutput',false)
result = cellfun(@(x)x,C2,'UniformOutput',false)
Now, to turn to your cell array:
new_mat
new_mat =
{[ 2.9473]} {[ 0.7736]} {[24.7335]} {[-32.1028]} {[ 5.4609]}
{[ 7.9357]} {[15.6115]} {[28.3915]} {[ 51.8624]} {[ 1]}
{[38.3376]} {[62.5463]} {[35.4955]} {[ 17.6059]} {[ 35.9168]}
{[15.0732]} {[24.9668]} {[ 3.2505]} {[-21.6557]} {0×0 double}
{[57.9756]} {[49.9486]} {[53.4301]} {[ 45.9361]} {[-17.1092]}
new_mat consists of 24 cells that contain a scalar and one cell that contains an empty array. The function you want to run is @(x)mean(x,1), which will return a scalar on each of the 24 cells containing scalars and will return an empty array on the cell that contains an empty array. Since not all results will be scalars, you must use 'UniformOutput',false. Of course, the mean of a scalar is the scalar itself and the mean of an empty array is an empty array, so the result you get is essentially what you started with (the difference is that the 0x0 empty array becomes 1x0 when passed through mean(x,1)).
result = cellfun(@(x)mean(x,1),new_mat,'UniformOutput',false)
result =
{[ 2.9473]} {[ 0.7736]} {[24.7335]} {[-32.1028]} {[ 5.4609]}
{[ 7.9357]} {[15.6115]} {[28.3915]} {[ 51.8624]} {[ 1]}
{[38.3376]} {[62.5463]} {[35.4955]} {[ 17.6059]} {[ 35.9168]}
{[15.0732]} {[24.9668]} {[ 3.2505]} {[-21.6557]} {1×0 double}
{[57.9756]} {[49.9486]} {[53.4301]} {[ 45.9361]} {[-17.1092]}
isequal(result([1:23 25]),new_mat([1:23 25]))
OK, so that's a cellfun primer. As I said, cellfun operates on each cell independently. But you want to operate on columns of cells together, so that makes cellfun ill-suited to the task. It's straightforward to write a loop to do what you want:
result(ii) = mean([new_mat{:,ii}]);
disp(result)
24.4539 30.7694 29.0602 12.3292 6.3171
which could also be written:
result(ii) = mean(vertcat(new_mat{:,ii}));
disp(result)
24.4539 30.7694 29.0602 12.3292 6.3171
The difference being that the first loop horizontally concantenates the contents of the cells in a given column, and the second loop vertically concatenates the contents of the cells in a given column. In either case the result of that concatenation is a vector, so no dimension argument is required for mean (that is, it's mean(x), not mean(x,1)), but you could include one (it would be 2 for the horizontal concatentation case and 1 for the vertical).
Note that the dimension argument sent to mean has nothing to do with how the cells are arranged in new_mat! You're wanting to do @(x)mean(x,1) because you are thinking of averaging a column of cells, but the function @(x)mean(x,1) when used in cellfun doesn't operate on a column of cells - it operates on one cell at a time. Each cell contains a scalar (or empty array), so the dimension argument passed in to mean() is irrelevant.
In order to take the mean of several elements at a time, you've got to concatenate them together somehow - that's what code inside the loops does ([new_mat{:,ii}] to horizontally concatenate the contents of the cells in the iith column of new_mat, or vertcat(new_mat{:,ii}) to concatenate the same things vertically).