I've written some short code for subtracting values of one wave from the next. The code does what I want except for the fact that I'd like to subtract the second point of wave 2 from the first point of wave 1 and so on such that I would have a third result wave with 1 less value than wave2. So far the code works until it gets to the last point which is spitting out 0 but which i'd like to be a Nan-- the algorithm should stop subtracting so the values of wave val should be 4,0,-1,8 and that's it.
function go()wave wave2
wave wave1
wave val
make/O/N = (numpnts(wave2)) val
variablex = 1variablep = 0print"val has ", numpnts(wave2)do
val[p] = wave2[x] - wave1[p]// if (x >= (numpnts(wave2)) || p >= (numpnts(wave1) -1))if(x == numpnts(wave2)||p == (numpnts(wave1) -1))
val[numpnts(wave2)] = NaNelsebreakendifx+=1p+=1while(1)end
function subtract()wave wave2
wave wave1
make/O/N = (numpnts(wave2)-1) val // one point shorter
val = wave2[p] - wave1[p+1]//if you really want an additional point with 'NaN', uncomment the next two lines//redimension/n=(numpnts(val)+1) val//val[numpnts(val)-1]=NaNend
You could also execute the middle two lines on the command line without needing a function for this operation. I do not know how experienced you are in Igor programming, but it seems to me like some important concepts of wave assignment operations are still somewhat unclear. I recommend you to read the help chapter about this by executing DisplayHelpTopic"Waveform Arithmetic and Assignment"
You could also execute the middle two lines on the command line without needing a function for this operation. I do not know how experienced you are in Igor programming, but it seems to me like some important concepts of wave assignment operations are still somewhat unclear. I recommend you to read the help chapter about this by executing
DisplayHelpTopic "Waveform Arithmetic and Assignment"
November 27, 2014 at 05:49 pm - Permalink
November 27, 2014 at 06:52 pm - Permalink