multi dimension colon operation

I don't know if 'multi dimension colon operation' can explain my question, what I hope to do is given a matrix:
matrix_in = [1, 2, 3;
2, 3, 4;
3, 4, 5];
for each of the i=1:3 line, return the sum of matrix_in from line 1 to line i, so the output is:
matrix_out = [1, 2, 3;
3, 5, 7;
6, 9, 12];
is there a way of doing this with one line code? Thanks!

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 9 月 24 日

2 投票

cumsum(matrix_in)

2 件のコメント

Xueqing
Xueqing 2015 年 9 月 24 日
that's nice and neat, thanks for the quick help!
Matt J
Matt J 2015 年 9 月 24 日
that's nice and neat, thanks for the quick help!
You should thank Azzi by clicking "Accept" on his answer.

この質問は閉じられています。

質問済み:

2015 年 9 月 24 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by