summing a column of a cell array

2 ビュー (過去 30 日間)
Thomas Roza
Thomas Roza 2019 年 12 月 1 日
コメント済み: Thomas Roza 2019 年 12 月 2 日
hi,
I have a 74x74 cell array and in each cell i have stored a vector it looks like this:
cell array.JPG
i would like to sum all the vectors in colomn 1 to 74 so a new vector is created, and stored in a 1x74 cell array, i haven't succeded so i hope you could help me, thank you!

採用された回答

Walter Roberson
Walter Roberson 2019 年 12 月 1 日
mat2cell(sum(cell2mat(fm)),1,cellfun(@(V) size(V,2), fm(:,1)))
Assumptions:
  • each cell contains a row vector
  • the cell can be converted to a matrix. (For example would fail for function handles)
  • the elements are a datatype for which sum() is defined
  • the size of each row vector is consistent for the column.
Not Assummed:
  • that the elements are numeric
  • that the length of the row vectors is exactly 3
  • that the length of the row vectors are all the same across the columns. For example if column 2 had row vectors of length 4, then this code would be happy to give you a result in which the second entry had length 4.
  1 件のコメント
Thomas Roza
Thomas Roza 2019 年 12 月 2 日
it worked perfectly! tanks a lot!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by