How to find mean of cells?

11 ビュー (過去 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 Center および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by