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

 採用された回答

Star Strider
Star Strider 2012 年 10 月 19 日
編集済み: Star Strider 2012 年 10 月 19 日

0 投票

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?

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 19 日

1 投票

A=rand(100,100,100);
out=sum(A,3)

カテゴリ

ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by