Misunderstanding interp function?
ahb
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)
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)
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:
xAverageWave[i]=leftborder+(i*(rightborder-leftborder)/1200)
endfor
write
p is an internal loop variable in Igor analogous to your i variable. For details execute:
Similarly change
//print interp(xAverageWave[i],xAverageWave,w)
AverageWave= AverageWave+interp(xAverageWave[i],xAverageWave,w[i])
endfor
to
November 14, 2013 at 10:27 am - Permalink
After useing wave(x) instead of interp the problem was solved even if I couldn't find the original error.
Have a nice week.
November 18, 2013 at 06:37 am - Permalink