Filter löschen
Filter löschen

Sum of cell array Line

3 Ansichten (letzte 30 Tage)
Marco Silva
Marco Silva am 7 Aug. 2019
Kommentiert: Adam Danz am 8 Aug. 2019
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

Akzeptierte Antwort

Adam Danz
Adam Danz am 7 Aug. 2019
Bearbeitet: Adam Danz am 8 Aug. 2019
% 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 Kommentare
Marco Silva
Marco Silva am 8 Aug. 2019
Thanks for the help, it works!
Adam Danz
Adam Danz am 8 Aug. 2019
Glad I could help!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by