Misunderstanding interp function?

Hello. Currently I am trying to average a couple of waves with different length. I am just interested in the central part of them.
So I determine the minimal values for the left and right borders of the shortest waves.
With this information I set the scale for the AverageWave. After that I try to get the y-values of from the different waves using the interp function.
But this doesn't seem to work. It justes gives me the first 1200 values from the waves instead of an interpolated value depending on xAverageWave[i].
Am I missing something or use it wrong?
Any help or eye opener would be appreciated.
Thanks a lot.


Make/N=1200 xAverageWave, AverageWave
Variable i
for(i=0;i<1200;i+=1)
	xAverageWave[i]=leftborder+(i*(rightborder-leftborder)/1200)
endfor
SetScale/I x,leftborder,rightborder, AverageWave
index=0
AverageWave=0
do
	wave w=$StringFromList(index,wavelist((wavenames+"*"),";",""))
	for(i=0;i<1200;i+=1)
                //print interp(xAverageWave[i],xAverageWave,w)
		AverageWave= AverageWave+interp(xAverageWave[i],xAverageWave,w)
	endfor	
	index+=1
while(strlen(StringFromList(index,wavelist("*Point*",";","")))!=0)
I don't see anything obviously wrong although the code is very inefficient (details below). If you can't figure it out create a simplified executable example with a small number of points that anyone can execute and debug. Something like:



Function Demo()
	Make/O/N=10 wave0=p, wave1=2*p
	SetScale/I x 0, 5, "", wave0, wave1
	
	Make/O/N=5 average = 0
	SetScale/I x 1, 4, average
	
	average += wave0(x)
	average += wave1(x)
	average /= 2
	
	if (WinType("DemoTable") == 0)
		Edit/N=DemoTable wave0.id, wave1.id, average.id
	endif
	
	if (WinType("DemoGraph") == 0)
		Display/N=DemoGraph wave0, wave1, average
	endif
End


Note that I did not use interp. If your input data is waveform data (has X scaling) then you can use the automatic interpolation provided by X indexing (wave0(x)).

If your input data is XY then you do need to use interp. Create a simplified executable example like the one above.

For efficiency and readability you should be using wave assignment statements instead of loops. For example, instead of:

for(i=0;i<1200;i+=1)
	xAverageWave[i]=leftborder+(i*(rightborder-leftborder)/1200)
endfor


write

	xAverageWave=leftborder+(p*(rightborder-leftborder)/1200)


p is an internal loop variable in Igor analogous to your i variable. For details execute:

DisplayHelpTopic "Waveform Arithmetic and Assignment"


Similarly change

	for(i=0;i<1200;i+=1)
                //print interp(xAverageWave[i],xAverageWave,w)
		AverageWave= AverageWave+interp(xAverageWave[i],xAverageWave,w[i])
	endfor


to


	AverageWave += interp(xAverageWave,xAverageWave,w)

Thanks a lot for your help and the guidance for more efficient programming.
After useing wave(x) instead of interp the problem was solved even if I couldn't find the original error.
Have a nice week.