Sum of first row and column, then second row and column ... and so on Take a non-empty matrix / numeric array containing positive integers as input. Return, in this order, the sums of the first row and column, then the second row and column and continue until there aren't any more rows or columns.

Suppose the input is:

2   10   10    2    4
9    7    7    2    9
1    7    6    2    4
7    1    4    8    9


Then the output should be:

45, 33, 16, 17


Because: 2+9+1+7+10+10+2+4=45, 7+7+1+7+2+9=33, 6+4+2+4=16, 8+9=17.

Test cases:

Test cases are on the following format:

Input
---
Output




5
---
5
..........

1  4
----
5
..........

7
2
---
9
..........

 8    3    7   10    3    7   10    1
10    7    5    8    4    3    3    1
 1    6    4    1    3    6   10    1
 2    3    8    2    8    3    4    1
---
62   40   33   18
..........

30    39    48     1    10    19    28
38    47     7     9    18    27    29
46     6     8    17    26    35    37
 5    14    16    25    34    36    45
13    15    24    33    42    44     4
21    23    32    41    43     3    12
22    31    40    49     2    11    20
---
320  226   235   263   135    26    20
..........

7   10    1
4    4    2
6    3    4
1    4   10
5    7    6
---
34   20   20


As arrays:

[[5]]
[[1,4]]
[[7],[2]]
[[8,3,7,10,3,7,10,1],[10,7,5,8,4,3,3,1],[1,6,4,1,3,6,10,1],[2,3,8,2,8,3,4,1]]
[[30,39,48,1,10,19,28],[38,47,7,9,18,27,29],[46,6,8,17,26,35,37],[5,14,16,25,34,36,45],[13,15,24,33,42,44,4],[21,23,32,41,43,3,12],[22,31,40,49,2,11,20]]
[[7,10,1],[4,4,2],[6,3,4],[1,4,10],[5,7,6]]




This is code-golf so the shortest solution in each language wins.
MATL, 16 bytes

&amp;n:w:!XlX:GX:1XQ


Try it online! Or verify all test cases.

Explanation

Consider, as an example, the input 

2   10   10    2    4
9    7    7    2    9
1    7    6    2    4
7    1    4    8    9


The code &amp;n:w:!Xl builds the column vector [1; 2; 3; 4] and the row vector [1 2 3 4 5]. Then Xl computes the minimum element-wise with broadcast, which gives the matrix

1 1 1 1 1
1 2 2 2 2
1 2 3 3 3
1 2 3 4 4


X: linearizes this matrix (in column-major order) into the column vector [1; 1; 1; 1; 1; 2; 2; ... ; 4]. This vector and the linearized input matrix, obtained as GX:, are passed as inputs to the accumarray(... @sum) function, or 1XQ. This computes the sum of the second input grouped by values of the first input.