Sum of cell array Line

3 visualizaciones (últimos 30 días)
Marco Silva
Marco Silva el 7 de Ag. de 2019
Comentada: Adam Danz el 8 de Ag. de 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

Respuesta aceptada

Adam Danz
Adam Danz el 7 de Ag. de 2019
Editada: Adam Danz el 8 de Ag. de 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 comentarios
Marco Silva
Marco Silva el 8 de Ag. de 2019
Thanks for the help, it works!
Adam Danz
Adam Danz el 8 de Ag. de 2019
Glad I could help!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by