sum a column per row with loops

2 vues (au cours des 30 derniers jours)
ahmad
ahmad le 3 Août 2022
Modifié(e) : DGM le 3 Août 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?

Réponse acceptée

DGM
DGM le 3 Août 2022
Modifié(e) : DGM le 3 Août 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

Plus de réponses (0)

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by