Simple way to add waves together

Samuel_S
Posts: 3
Joined: 2017-09-04
Location: Sweden

Greetings everyone.

I must admit I am somewhat new in using IGOR, and haven't figured out all its strengths yet.

My problem is the following:

I have a large set of waves, 480 to be more precise, and I would like to add them (or a subset of them) together in a simple way.

That is, I want the first data point in wave0 to be added to the first point of wave1 and the second data points added together etc. These waves are number from 0 to 479 and have a total of 640 data points.

I tried to simply use the command window to write (after making a new 640 point empty wave called waveX): "waveX = wave0" follwed by "waveX = waveX + wave1" etc up to wave479. It seemed to work, but it took forever. Also, using this strategy it is very bothersome to change the number of waves to be added together, such as if I want to limit myself to wave200 - wave300 or something similar.

Does anyone have an idea how to do this in a fast and easy way?

Samuel

kanekaka
Posts: 18
Joined: 2010-08-24
Location: Japan

```Macro SumAllWaves()
String sList = WaveList("*", ";", "")
Variable vNum = ItemsInList(sList), i = 0
Make /O/N=640 waveX
waveX = \$StringFromList(i, sList)
i = 1
do
waveX += \$StringFromList(i, sList)
i += 1
while(i < vNum)
end```

ChrLie
Posts: 266
Joined: 2009-01-06
Location: Switzerland

Make a matrix from your 1D wave using Concatenate and then use MatrixOP. Assuming the only waves in the current datafolder are the ones to be summed up, you could execute:

```concatenate/O/NP=1 WaveList("*",";",""), M_AllWaves
MatrixOP/O WaveX = sumrows(M_AllWaves)```

Samuel_S
Posts: 3
Joined: 2017-09-04
Location: Sweden

I am a bit unsure of what the following line means:

WaveList("*", ";", "")

More precisely, what sort of text I should put in it. The wave folder has more waves in it than I want to sum together. Every "wavename" so to speak comes with waves, one for energy and one for intensity. So Ene_[wavename]0 and Int_[wavename]0.

Does that mean I should put something into the WaveList command?

ChrLie
Posts: 266
Joined: 2009-01-06
Location: Switzerland

if you execute

`DisplayHelpTopic "WaveList"`

from the command line you'll get examples how the WaveList command works. If you want to sum up the intensities, you would use:

`WaveList("Int_*", ";", "")`

Just be careful that there are no waves starting with "Int_" that you don't want to include in the sum.

[ last edited September 11, 2017 - 04:26 ]
Samuel_S
Posts: 3
Joined: 2017-09-04
Location: Sweden

Thanks again! You have been really helpful.