How to take average of such an array?

조회 수: 1 (최근 30일)
Prashant Bhagat
Prashant Bhagat 2022년 8월 18일
답변: Stephen23 2022년 8월 18일
Z =
6×2 cell array
{[1 0 2 2 1 1 3 1 1 0]} {[2 1 0 0 0 1 0 2 0 0]}
{[2 2 3 3 1 3 3 2 1 0]} {[2 2 0 0 1 2 0 2 0 0]}
{[2 3 3 3 2 3 4 2 1 0]} {[3 5 0 0 1 3 0 3 0 1]}
{[2 3 3 5 2 3 6 3 1 1]} {[3 5 1 0 1 4 0 4 0 1]}
{[2 4 3 5 2 3 6 3 1 2]} {[4 5 2 0 1 5 0 5 2 2]}
{[2 5 3 7 3 4 6 3 1 3]} {[5 5 2 0 3 5 1 6 4 3]}

채택된 답변

Stephen23
Stephen23 2022년 8월 18일
Z = {[1,0,2,2,1,1,3,1,1,0],[2,1,0,0,0,1,0,2,0,0];[2,2,3,3,1,3,3,2,1,0],[2,2,0,0,1,2,0,2,0,0];[2,3,3,3,2,3,4,2,1,0],[3,5,0,0,1,3,0,3,0,1];[2,3,3,5,2,3,6,3,1,1],[3,5,1,0,1,4,0,4,0,1];[2,4,3,5,2,3,6,3,1,2],[4,5,2,0,1,5,0,5,2,2];[2,5,3,7,3,4,6,3,1,3],[5,5,2,0,3,5,1,6,4,3]}
Z = 6×2 cell array
{[1 0 2 2 1 1 3 1 1 0]} {[2 1 0 0 0 1 0 2 0 0]} {[2 2 3 3 1 3 3 2 1 0]} {[2 2 0 0 1 2 0 2 0 0]} {[2 3 3 3 2 3 4 2 1 0]} {[3 5 0 0 1 3 0 3 0 1]} {[2 3 3 5 2 3 6 3 1 1]} {[3 5 1 0 1 4 0 4 0 1]} {[2 4 3 5 2 3 6 3 1 2]} {[4 5 2 0 1 5 0 5 2 2]} {[2 5 3 7 3 4 6 3 1 3]} {[5 5 2 0 3 5 1 6 4 3]}
M = mean(cell2mat(permute(Z,[1,3,2])),3)
M = 6×10
1.5000 0.5000 1.0000 1.0000 0.5000 1.0000 1.5000 1.5000 0.5000 0 2.0000 2.0000 1.5000 1.5000 1.0000 2.5000 1.5000 2.0000 0.5000 0 2.5000 4.0000 1.5000 1.5000 1.5000 3.0000 2.0000 2.5000 0.5000 0.5000 2.5000 4.0000 2.0000 2.5000 1.5000 3.5000 3.0000 3.5000 0.5000 1.0000 3.0000 4.5000 2.5000 2.5000 1.5000 4.0000 3.0000 4.0000 1.5000 2.0000 3.5000 5.0000 2.5000 3.5000 3.0000 4.5000 3.5000 4.5000 2.5000 3.0000

추가 답변 (1개)

KSSV
KSSV 2022년 8월 18일
편집: KSSV 2022년 8월 18일
% Make data for demo
A = cell(6,2) ;
for i = 1:6
for j = 1:2
A{i,j} = rand(1,10) ;
end
end
% Get mean
iwant = cellfun(@mean,A)
iwant = 6×2
0.4699 0.4161 0.6041 0.3679 0.5048 0.4849 0.3682 0.4060 0.4757 0.3761 0.3571 0.4127
Or you can also run loop.
  댓글 수: 1
Prashant Bhagat
Prashant Bhagat 2022년 8월 18일
Actually, I didn't exlain my question very well. Actually I want to take average of elemnet of array. So
Z =
6×2 cell array
{[1 0 2 2 1 1 3 1 1 0]} {[2 1 0 0 0 1 0 2 0 0]}
{[2 2 3 3 1 3 3 2 1 0]} {[2 2 0 0 1 2 0 2 0 0]}
{[2 3 3 3 2 3 4 2 1 0]} {[3 5 0 0 1 3 0 3 0 1]}
{[2 3 3 5 2 3 6 3 1 1]} {[3 5 1 0 1 4 0 4 0 1]}
{[2 4 3 5 2 3 6 3 1 2]} {[4 5 2 0 1 5 0 5 2 2]}
{[2 5 3 7 3 4 6 3 1 3]} {[5 5 2 0 3 5 1 6 4 3]}
the result should be like { [ 1.5 0.5 1 1 0.5 1 1.5 1.5 0.5 0] } for the underlined part of the cell array. I want to do this for rest of the cell array.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by