How to take Mean of cell array ?
41 次查看(过去 30 天)
显示 更早的评论
Hi
I have a struct variable A with 1x15 cell, where each cell array is of variable size in it's 1st dimension and other two dimensions are fixed. i.e dimension of 1st cell array is 200x1x120 and of 2nd it is 120x1x120, I want to take the mean of all the cell arrays in variable A How i can do that please.?
0 个评论
回答(1 个)
Ameer Hamza
2020-4-17
See cellfun(): https://www.mathworks.com/help/matlab/ref/cellfun.html
A_averaged = cellfun(@(x) mean(x, 'all'), A);
2 个评论
Ameer Hamza
2020-4-17
'x' is the variable of anonymous function. This has no effect if there is an x defined in your code. The scope of this 'x' is just inside the anonymous function.
@(x) mean(x, 'all')
cellfun takes each element of cell array A and applies the anonymous function on it.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!