フィルターのクリア

multi-dimensional array - summing the layers (combining)

2 ビュー (過去 30 日間)
philio63
philio63 2022 年 5 月 22 日
コメント済み: philio63 2022 年 5 月 22 日
is there a way to combine (or sum) the layers of a multi-dimensional array
essentially, I have an array of multiple layers
p1(i,j,k)
and it outputs
val(:,:,1) =
1 2 3
4 5 6
val(:,:,2) =
2 2 2
2 2 2
What I'd like to do is, sum each layer, and then turn it into:
3 4 5
6 7 8
is there a function that can "sum" all the layers in an array. Essentially, I'm flattening the array, making it 2D.
Many thanks!

採用された回答

DGM
DGM 2022 年 5 月 22 日
To sum along a given dimension:
dim3sum = sum(val,3);
  1 件のコメント
philio63
philio63 2022 年 5 月 22 日
beautiful!
Thank you very much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by