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!