How to find mean of cells?
11 次查看(过去 30 天)
显示 更早的评论
I have a cell array 'x' with 1x5 cell class. Now, in x{1,1} has 2x1 cell. Now i would like to find nanmean of (x{1, 1}{1, 1}(5,4)+x{1, 1}{2, 1}(5,4))
Now in xx{1,2} has 4x1 cell. Now i would like to find nanmean of (x{1, 1}{1, 1}(5,4)+x{1, 1}{2, 1}(5,4))
So, In a way it is a nanmean by each elements between two cells.
Can anyone help for this...?
0 个评论
回答(1 个)
OCDER
2018-10-23
You should consider extracting your variables out from cell arrays to simple matrices. Then you can use nanmean. Here are some common functions for extracting data from cell arrays.
cell2mat : cell2mat(C) convert cell to matrix
vertcat : vertcat(C{:}) will concatenate cell into matrix, vertically
horzcat : horzcat(C{:}) will concatenate cell into matrix, horizontally
cellfun : cellfun(@(x) x(1), C) go through each cell element to do something.
Example:
X = {[1,2] [2,3] [3,4]};
X = cell2mat(X(:));
nanmean(X, 2)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!