A= [ 1 2 4
2 3 1
3 1 2 ]
以便上面矩阵的答案应该是:
B = [ 1 3 7
9 12 13
16 17 19 ]
感谢
答案 0 :(得分:5)
摆弄cumsum
和reshape
可以帮助您:
B = reshape(cumsum(reshape(A', 1, [])), size(A))'
%# Equivalent to: B = A'; B = reshape(cumsum(B(:)), size(A))'
这会产生:
B =
1 3 7
9 12 13
16 17 19