Average of Row Elements in a Multideminsional Array
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Nate
el 30 de Sept. de 2014
Comentada: Nate
el 30 de Sept. de 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.
0 comentarios
Respuesta aceptada
Andrei Bobrov
el 30 de Sept. de 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);
Más respuestas (0)
Ver también
Categorías
Más información sobre Multidimensional Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!