adding the vectors at each cell in cell array

5 ビュー (過去 30 日間)
Romio
Romio 2020 年 7 月 13 日
コメント済み: Romio 2020 年 7 月 13 日
Hi
I have a cell array where each cell contains a vector. I want to add up the vectors at each cell of each row.
The cell array is
M = cell(1,1) cell (1,2) ........
cell(2,1) cell(2,2) .......
and so on
If we have the vector a_11 = [1 2 3 4 5] in cell(1,1) and a12 = [1,2,3,4,5] in cell(1,2), I want to add them so that the sum is [1+1 2+2 3+3 4+4 5+5] = [2 4 6 8 10]
then I want to store the result in a matrix whose rows is equal to the rows of the cell array, and columns equal to the length of the vectors (i.e. 5)
Could someone help me pleas?
Thanks

採用された回答

Walter Roberson
Walter Roberson 2020 年 7 月 13 日
cell2mat( arrayfun(@(R) sum(cat(1,M{R,:})), (1:size(M,1)).', 'uniform', 0) )
  1 件のコメント
Romio
Romio 2020 年 7 月 13 日
Thank you!

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by