フィルターのクリア

Adding elements of 3D matrices

3 ビュー (過去 30 日間)
N Madani SYED
N Madani SYED 2012 年 7 月 3 日
Hi all,
Suppose A(10,10,3) and I need to add the elements of A to get B(10,10,1) such that B(1,1,1) = A(1,1,1)+A(1,1,2)+A(1,1,3); B(1,2,1) = A(1,2,1)+A(1,2,2)+A(1,2,3); B(2,2,1) = A(2,2,1)+A(2,2,2)+A(2,2,3); and so on. This without using for loop.
Regards N. M. Syed

採用された回答

Sean de Wolski
Sean de Wolski 2012 年 7 月 3 日
B = sum(A,3);
  1 件のコメント
N Madani SYED
N Madani SYED 2012 年 7 月 3 日
Thanks

サインインしてコメントする。

その他の回答 (1 件)

Thomas
Thomas 2012 年 7 月 3 日
編集済み: Thomas 2012 年 7 月 3 日
a(:,:,1)=[1 2 3;4 5 6;7 8 9];
a(:,:,2)=[1 2 3;4 5 6;7 8 9];
a(:,:,3)=[1 2 3;4 5 6;7 8 9];
b=a(:,:,1)+a(:,:,2)+a(:,:,3)
or
b=sum(a,3)
  1 件のコメント
N Madani SYED
N Madani SYED 2012 年 7 月 3 日
Thanks

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix and Vector Construction についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by