フィルターのクリア

Sum of cell array Line

3 ビュー (過去 30 日間)
Marco Silva
Marco Silva 2019 年 8 月 7 日
コメント済み: Adam Danz 2019 年 8 月 8 日
Hi,
I have a cell array and i need to get the sum of line 4. My cell array is:
A(4,:) =
1×25 cell array
Columns 1 through 8
{0×0 double} {1×45 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
Columns 9 through 16
{0×0 double} {0×0 double} {0×0 double} {1×45 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
Columns 17 through 24
{0×0 double} {1×45 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {1×45 double} {0×0 double}
Column 25
{0×0 double}
The problem is, I need my result in format 1x45 double. I need to add each element individually.
Like this,
If A(4,2) = { 1 2 3 4 5} and A(4, 12) = { 6 7 8 9 10} my result should be: Result = { 3.5 4.5 5.5 6.5 7.5}
how can i do this?
Thanks

採用された回答

Adam Danz
Adam Danz 2019 年 8 月 7 日
編集済み: Adam Danz 2019 年 8 月 8 日
% When elements of A are row vectors of the same length
% (like the example in the question)
s = sum(cell2mat(A{4}.'),1);
% When elements of A are column vectors of the same length
s = sum(cell2mat(A{4}),2);
  2 件のコメント
Marco Silva
Marco Silva 2019 年 8 月 8 日
Thanks for the help, it works!
Adam Danz
Adam Danz 2019 年 8 月 8 日
Glad I could help!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by