All pastes #915380 Raw Edit

Someone

public text v1 · immutable
#915380 ·published 2008-02-23 19:24 UTC
rendered paste body
Calculate Row and Column Sums!
----------------------------------------------------------------------
Write a function that from a matrix A computes another matrix B of the
same dimension, where each entry in B is the row and column sum of the
elements in A, that is to say:


            m            n
           --.          --. 
  b    =   \  a     +   \   a   
   ij      /_,  ik      /_,  lj
           k=1          l=1

where m and n denotes the number of rows and columns, respectively.


Syntax: B = matsum(A)
        -------------

where B is the output matrix and
      A the input matrix.


Basic functionality:


>> A = [1 2 3; 4 5 6]

A =

     1     2     3
     4     5     6

>> B = matsum(A)

B =

     11    13    15
     20    22    24


A correct solution gives one point if it passes a test similar to the
example above.