sumarray

sumarray — returns the sum of the elements in an array.

Description

The sumarray opcode returns the sum of all elements in a k-rate array array.

Syntax

ksum sumarray karray

Performance

ksum -- variable for result.

karray -- array for reading.

Examples

Here is an example of the sumarray opcode. It uses the file sumarray.csd.

Example 1045. Example of the sumarray opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-n 
</CsOptions>
<CsInstruments>
;example by joachim heintz

           seed       0

instr 1
;create an array with 10 elements
kArr[]     init       10
;fill in random numbers and print them out
kIndx      =          0
  until kIndx == 10 do
kNum       random     0, 10
kArr[kIndx] =         kNum
           printf     "kArr[%d] = %10f\n", kIndx+1, kIndx, kNum
kIndx      +=         1
  od
;calculate sum of all values and print it out
kSum       sumarray   kArr
           printf     "Sum of all values in kArr = %f\n", kIndx+1, kSum
           turnoff
endin
</CsInstruments>
<CsScore>
i1 0 0.1
e
</CsScore>
</CsoundSynthesizer>


See Also

minarray, sumarray, scalearray,

Credits

Author: John ffitch
October 2011

New in Csound version 5.14

Revised in Csound version 6.00 to work on multidimensional arrays