sum a column per row with loops

1 Ansicht (letzte 30 Tage)
ahmad
ahmad am 3 Aug. 2022
Bearbeitet: DGM am 3 Aug. 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?

Akzeptierte Antwort

DGM
DGM am 3 Aug. 2022
Bearbeitet: DGM am 3 Aug. 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

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