Reduce one dimension of a array by using sum
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
Star Strider
am 19 Okt. 2012
Bearbeitet: Star Strider
am 19 Okt. 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?
0 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!