Reduce one dimension of a array by using sum

15 visualizaciones (últimos 30 días)
hung lequang
hung lequang el 19 de Oct. de 2012
Hello,
Can anyone show me how I can reduce one dimension of the following array without using for loops. Thanks!
A=rand(100,100,100);
for ith = 1:100
for jth = 1:100
B(ith,jth) = sum(A(ith,:,jth))
end
end

Respuesta aceptada

Star Strider
Star Strider el 19 de Oct. de 2012
Editada: Star Strider el 19 de Oct. de 2012
If you are summing across the second dimension of your three-dimension array A, the easiest way would be to use the ‘dim’ argument of sum:
B = squeeze(sum(A,2))
Does this do what you want?

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 19 de Oct. de 2012
A=rand(100,100,100);
out=sum(A,3)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by