Pergunta

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

so that the answer from above matrix should be:

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

thanks

Foi útil?

Solução

Fiddling with cumsum and reshape can get you there:

B = reshape(cumsum(reshape(A', 1, [])), size(A))'
%# Equivalent to: B = A'; B = reshape(cumsum(B(:)), size(A))'

This yields:

B =

     1     3     7
     9    12    13
    16    17    19
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top