- Scilab Online Help
- Elementary Functions
- Discrete mathematics
- Floating point
- Integer representation
- Trigonometry
- abs
- amell
- and
- &
- binomial
- bitand
- bitor
- bloc2exp
- bloc2ss
- cat
- cell2mat
- cellstr
- char
- cumprod
- cumsum
- delip
- diag
- diff
- dsearch
- exp
- eye
- flipdim
- gsort
- imag
- imult
- ind2sub
- intersect
- inttrap
- isdef
- isempty
- isequal
- isequalbitwise
- isreal
- isvector
- kron
- lex_sort
- linspace
- log
- log10
- log1p
- log2
- logm
- logspace
- lstsize
- max
- meshgrid
- min
- modulo
- ndgrid
- ndims
- nextpow2
- norm
- ones
- or
- |
- pen2ea
- permute
- pertrans
- prod
- rand
- real
- resize_matrix
- setdiff
- sign
- signm
- size
- solve
- sqrt
- sqrtm
- squarewave
- ssrand
- sub2ind
- sum
- sysconv
- sysdiag
- syslin
- toeplitz
- trfmod
- trianfml
- tril
- trisolve
- triu
- typeof
- union
- unique
- vectorfind
- zeros
Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function
sum
sum of array elements
Calling Sequence
y=sum(x) y=sum(x,orientation) y=sum(x,outtype) y=sum(x,orientation,outtype)
Arguments
- x
an array of reals, complex, booleans, polynomials or rational fractions.
- orientation
it can be either
a string with possible values
"*"
,"r"
,"c"
or"m"
a number with positive integer value
- outtype
a string with possible values
"native"
or"double"
.- y
scalar or array
Description
For an array x
,
y=sum(x)
returns in the scalar y
the
sum of all the elements of x
.
y=sum(x,orientation)
returns in
y
the sum of x
along the
dimension given by orientation
:
if
orientation
is equal to 1 or "r" thenor
if
orientation
is equal to 2 or "c" then:or
if
orientation
is equal to n theny=sum(x,"*")
is equivalent toy=sum(x)
y=sum(x,"m")
is equivalent toy=sum(x,orientation)
whereorientation
is the index of the first dimension ofx
that is greater than 1.
The outtype
argument rules the way the summation is done:
For arrays of floats, of polynomials, of rational fractions, the evaluation is always done using floating points computations. The
"double"
or"native"
options are equivalent.For arrays of integers,
if
outtype="native"
the evaluation is done using integer computations (modulo 2^b, where b is the number of bits used),if
outtype="double"
the evaluation is done using floating point computations.The default value is
outtype="native"
.For arrays of booleans,
if
outtype="native"
the evaluation is done using boolean computations ( + is replaced by |),if
outtype="double"
the evaluation is done using floating point computations (%t values are replaced by 1 and %f values by 0).The default value is
outtype="double"
.
Remark
This function applies, with identical rules to sparse matrices and hypermatrices.
Examples
<< sub2ind | Elementary Functions | sysconv >> |