A= [ 1 2 4
2 3 1
3 1 2 ]
因此,上述矩阵的答案应该是:
B = [ 1 3 7
9 12 13
16 17 19 ]
谢谢
摆
弄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