Sum of all elements in a single wave
j s s
Hi all,
I have a wave with one column and a lot of rows. I want to take the sum of all the elements in the wave. Other than copying and pasting the table into an excel and using the summation function, is there a way to code it in Igor?
I got this far, but obviously it's not going from i to N. Thanks in advance
function WaveSum (Dep_E)
wave Dep_E
variable N=numpnts(Dep_E),Sum, i
for (i=0; i<(N); i+=1)
Sum = Dep_E[i]+Dep_E[i+1]
endfor
print Sum
end
wave Dep_E
variable N=numpnts(Dep_E),Sum, i
for (i=0; i<(N); i+=1)
Sum = Dep_E[i]+Dep_E[i+1]
endfor
print Sum
end
If I understand correctly, you would need only use the "sum" function itself. For example. In your case you would call
print sum(Dep_E)
Taking the guided tour of Igor Pro might help you get more familiar with this and other functions/operations. You can access it from the Help Menu, clicking "Open Online Manual" under the manual tab, then going to the "Getting Started" section in the manual that opens.
September 24, 2018 at 01:11 pm - Permalink
Hi,
I would like to clarify your request a bit.
You mention you have a wave with 1 column and lots of rows. I take this to mean you have a 1-dimensional wave.
If this is the case then the Sum function does what you want
total = sum(Dep_E)
Also notice the color of the your declared variable Sum. It is doing that because it is a reserved word, a function in this case.
Andy
September 24, 2018 at 01:14 pm - Permalink
In addition to the sum() function, there is also
print V_Sum, V_sdev
MatrixOP/O W_Sum = sum(Dep_E) // may be more efficient for large waves
print W_sum[0]
September 25, 2018 at 01:15 am - Permalink