How to find mean of cells?

16 次查看(过去 30 天)
Megha
Megha 2018-10-23
评论: Megha 2018-10-23
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...?

回答(1 个)

OCDER
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)
  1 个评论
Megha
Megha 2018-10-23
Can you please give example of 2-dimensional matrix?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by