2
A= [ 1 2 4
     2 3 1
     3 1 2 ]

所以上面矩阵的答案应该是:

B = [ 1  3  7 
      9 12 13 
     16 17 19 ]

谢谢

4

1 回答 1

5

摆弄cumsumreshape可以让你到达那里:

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
于 2012-07-17T07:04:24.687 回答