Sum up elements in cells

5 ビュー (過去 30 日間)
cniv_we
cniv_we 2016 年 11 月 2 日
編集済み: Jan 2016 年 11 月 7 日
I want to sum up elements in cells so that a product of the sum is a matrix. The cell is for instance A{i,j}, with each cell contains a matrix B(p,q).
Now I want to matrix C which is a sum of each matrix in the cell A, so:
B_A{i,j} means matrix B(p,q) from cell A{i,j}
B_A{1,1} + B_A{1,2} + ... + B_A{1,j}
B_A{2,1} + B_A{2,2} + ... + B_A{2,j}
...
B_A{i,1} + B_A{i,2} + ... + B_A{i,j}*
and then sum again all the columns, so that matrix C has also dimension of pxq.
I am trying something like this:
C = A{i,:} + A{:,i} + A{j,:} + A{:,j};
However matrix dimensions is exceeded?
  1 件のコメント
Adam
Adam 2016 年 11 月 2 日
It would help if you could give a simple example, I'm not sure I follow from your description.

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

採用された回答

Jan
Jan 2016 年 11 月 2 日
編集済み: Jan 2016 年 11 月 7 日
Perhaps you mean this:
S = 0;
for k = 1:numel(A)
S = S + A{k};
end
Alternatively (faster processing, more temporary RAM required):
C = cat(3, A{:});
S = sum(C, 3);
  1 件のコメント
cniv_we
cniv_we 2016 年 11 月 7 日
That is exactly what I need. Thank you.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by