How to find mean of cells?

조회 수: 21 (최근 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