Matlab: mean and stddev in a cell -
in single array it's pretty simple mean
or standard deviation (std
) of numbers, in cell, data doesn't have same size in each of positions couldn't mean2
or std2
.
i know it's possible if copy of data in single row or single column wanted ask if knows if there single formula it?
thanks
you can use cellfun
compute per-cell mean
, std
:
cell_mean = cellfun(@mean, my_cell); cell_std = cellfun(@std, my_cell);
for example:
>> my_cell = {[1,2,3,6,8], [2,4,20]} >> cellfun(@mean, my_cell) ans = 4.0000 8.6667 >> cellfun(@std, my_cell) ans = 2.9155 9.8658
if want mean
and/or std
of elements in cells, can:
>> mean([my_cell{:}]) ans = 5.7500 >> std([my_cell{:}]) ans = 6.2048
and, if cell elements of different sizes, can use cell2mat
assist you:
>> mean(cell2mat(cellfun(@(x) x(:)', my_cell, 'uni', 0))) ans = 5.7500 >> std(cell2mat(cellfun(@(x) x(:)', my_cell, 'uni', 0))) ans = 6.2048
Comments
Post a Comment