sum a column per row with loops

1 visualizzazione (ultimi 30 giorni)
ahmad
ahmad il 3 Ago 2022
Modificato: DGM il 3 Ago 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?

Risposta accettata

DGM
DGM il 3 Ago 2022
Modificato: DGM il 3 Ago 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

Più risposte (0)

Categorie

Scopri di più su Multidimensional Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by