how to calculate a mean of an cell array

조회 수: 2 (최근 30일)
bay rem
bay rem 2015년 12월 13일
댓글: Image Analyst 2015년 12월 13일
  • i have a 3*6 matrix
m=[pc oc rc;
yc centroid ic;
ec uc hc]
  • where each value (pc, or...) define x,y coordonates of a pixel, then i converted this matrix to an cell array with :
c=mat2cell(m,ones(1,size(m,1)),2*ones(1,size(m,2)/2))
  • here i want to calcule a mean of this cell array:*
A=[mean(reshape(cell2mat(c), [2, 3, 3]), 3)]
  • but the result is not that one i want :(, i want to know where the problem is and how can i correct it

채택된 답변

Image Analyst
Image Analyst 2015년 12월 13일
Why are you using cell arrays? Why not just take the mean of m before doing any cell array stuff? Make m a 3D array instead of a cell array if you have multiple copies of m, then take the mean.
mMean = mean(m, 3)
  댓글 수: 2
bay rem
bay rem 2015년 12월 13일
here the 3*6 matrix:
m =
28 195 29 195 30 195
28 194 29 194 30 194
28 193 29 193 30 193
when i apply what you said here the result
mOY =
28 195 29 195 30 195
28 194 29 194 30 194
28 193 29 193 30 193
i think you mean "mMean = mean(m, 1)
Image Analyst
Image Analyst 2015년 12월 13일
I wasn't really sure what numbers you wanted to include in the mean. Like if it's the mean of the rows, mean of the columns, or mean of the whole m array. I still don't know. But I know it will be easier if you avoid cells and just use regular numerical arrays, even if you have to use a third dimension.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by