필터 지우기
필터 지우기

mean of each column of a cell array that contains cell arrays

조회 수: 3 (최근 30일)
Peter P
Peter P 2017년 12월 20일
댓글: Nandini Chatterjee 2020년 4월 9일
I have a cell array A(2x82). Cell array A contains in each cell cell arrays of different row sizes but equal column sizes. To be specific the column sizes are always 1.
First I want to combine the two rows of A and then calculate the mean of each column of cell array A. As a result i would get a 1x82 matrix.
Any suggestion? Thanks in advance, Peter
  댓글 수: 2
Walter Roberson
Walter Roberson 2017년 12월 20일
You have a 2 x 82 cell array of column vectors. When you take the mean of each column, I would expect a 2 x 82 numeric result, not a 1 x 82 numeric result.
Peter P
Peter P 2017년 12월 20일
편집: Peter P 2017년 12월 20일
You are right! I forgot to mention that I want to first combine the two rows of A and then calculate the mean. Any thoughts?

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2017년 12월 20일
cellfun(@mean, A) %provided you want a 2 x 82 numeric result.

추가 답변 (1개)

Jos (10584)
Jos (10584) 2017년 12월 20일
Another approach, as all cells contain a column vector:
M = arrayfun(@(k) mean([A(k,1) ; A(k,2)]), 1:size(A,1))
  댓글 수: 4
Walter Roberson
Walter Roberson 2020년 4월 9일
size(A,2) is the size of the second dimension of the array A -- the number of columns. 1:size(A,2) is then a vector of numbers, 1, 2, 3, 4, ... until the number of columns of A

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by