Search code examples
matlabcellaverage

determine average length of cells in a cell array


Hi I have a cell array in matlab, where the cells are of differing lengths. how do i determine the average length of the cells.

I have tried:

mean(length(mycell{:});

however this is too many inputs for the mean function.

Thanks.


Solution

  • Use cellfun

    mean( cellfun( @length, mycell ) )
    

    BTW, for some of the builtin functions it might be better to write

    mean( cellfun( 'length', mycell ) )