Average of Row Elements in a Multideminsional Array
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a 1 x 10 cell array, with each cell containing an 890 x 2 double. I need to find the mean across each row for all cells for values in the 2nd column (while ignoring the 1st column in each cell). The output would therefore simply be a 890 x 1 double (vector).
As a simple example, consider a 1 x 3 cell array A{}
A = {[5 7 ; 0 1 ; 4 3 ] [1 0 ; 3 5 ; 9 8 ] [9 2 ; 3 9; 2 1 ]}
A{1}
ans =
5 7
0 1
4 3
A{2}
ans =
1 0
3 5
9 8
A{3}
ans =
9 2
3 9
2 1
What I want is the following output, for example to B.
B
ans =
3 % This is just 7 + 0 + 2 / 3
5 % 1 + 5 + 9 / 3
4 % 3 + 8 + 1 / 3
Any help on coding this is appreciated - I am happy to do it using a for loop, no problem, if possible.
댓글 수: 0
채택된 답변
Andrei Bobrov
2014년 9월 30일
one way
A2 = cellfun(@(x)x(:,2),A,'un',0);
B = mean([A2{:}]',2);
other way
A3 = cat(A,3);
B = mean(A3(:,2,:),3);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!