필터 지우기
필터 지우기

Average of Row Elements in a Multideminsional Array

조회 수: 2 (최근 30일)
Nate
Nate 2014년 9월 30일
댓글: Nate 2014년 9월 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.

채택된 답변

Andrei Bobrov
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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by