sum computes the sum of all elements for a real or complex vector. Strings from string vectors will be appended to a scalar string. When the argument is a matrix, a row vector will be created containing the sum of the matrix columns.

mSum = sum(m)

Return Value

mSum is a scalar if m is a vector. The scalar contains the sum of vector elements. If m is a matrix, mSum is a row vector. The row vector’s columns contain the sum of matrix rows m.



m is a real, complex or string matrix.


There is a set of functions in UniScript which edit their arguments columnwise when it is a matrix: i.e. all, any, max, min.


* m = rand(4,3)
* m
    0.3237     0.3530     0.3255
    0.3244     0.1540     0.3401
    0.4934     0.5662     0.8952
    0.2887     0.8207     0.3366
* sum(m)
    1.4302     1.8939     1.8974
* sum(sum(m))