How to sum up multiple cell arrays (column-wise)?

6 ビュー (過去 30 日間)
Jake
Jake 2023 年 1 月 16 日
編集済み: Matt J 2023 年 1 月 16 日
I have a set of data in the form of a 26x32 cell array. Each cell consists a 6x6 matrix. I have attached the dummy file here.
How can I sum up the values of each column, so the output is again a 1x32 cell array, where each cell contains a 6x6 matrix?
Thanks in advance!

採用された回答

Matt J
Matt J 2023 年 1 月 16 日
A=load('dummy').dA_dum;
B=reshape( cell2mat(A(:).') ,6,6,26,32);
result =reshape( num2cell(sum(B,3),[1,2]) ,1,32);
  2 件のコメント
Jake
Jake 2023 年 1 月 16 日
Thank you, Matt. This does the job nicely!
I'm simply curious though, is there a way to do this without reshaping the cell array? Or rather, without using cell2mat?
Matt J
Matt J 2023 年 1 月 16 日
編集済み: Matt J 2023 年 1 月 16 日
You can use a plain vanilla for-loop... I don't really understand why you are using cell arrays to begin with, since in your case the cell contents are all the same size. If you just hold things in the numeric form B instead, the summation is quite trivial, as you can see.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by