sum a column per row with loops

1 visualización (últimos 30 días)
ahmad
ahmad el 3 de Ag. de 2022
Editada: DGM el 3 de Ag. de 2022
let say i have a 10x10 matrix of ones
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
how can i sum every column of the matrix, per rows like this
1 = 2 = 3 ...
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
and so on?

Respuesta aceptada

DGM
DGM el 3 de Ag. de 2022
Editada: DGM el 3 de Ag. de 2022
I'm going to assume you mean to do a cumulative sum of rows:
A = ones(5) % a smaller example
A = 5×5
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
B = cumsum(A,2)
B = 5×5
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5

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