Filter löschen
Filter löschen

Average of Row Elements in a Multideminsional Array

1 Ansicht (letzte 30 Tage)
Nate
Nate am 30 Sep. 2014
Kommentiert: Nate am 30 Sep. 2014
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.

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 30 Sep. 2014
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);

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by