Find all 0 of the wave
mcphyenergy
I am new of Igor, and I search to make a table with all cordinates where my wave=0.
I have a wavetime, and on the wavetime, I have cycles of time, but cycles are not the same length, so I want to find all the row when the wavetime=0 and put it on the table.
Thanks for your help.
wave yourwave
variable i,j=0
make/o/n=(numpnts(yourwave)) outputwave
for (i=0;i<=numpnts(yourwave);i+=1)
if (yourwave[i] == 0)
outputwave[j] = i
j = j+1
endif
endfor
edit
appendtotable outputwave
end
That will give you an outputwave with the point positions of the zeros in order. Up to you what you do with it from there.. You can of course change the names or use references etc..
September 5, 2012 at 05:53 am - Permalink
September 5, 2012 at 08:15 am - Permalink
September 5, 2012 at 11:15 am - Permalink
wave inwave
string sname = NameOfWave(inwave)+"_0"
duplicate/O inwave, $sname
wave zwave=$sname
zwave = (inwave[p]==0) ? p : NaN
WaveTransform zapNaNs, zwave // optional
end
This also offers an auto-naming feature to the wave with zero locations. The last line in the function removes the NaNs from the wave, and reduces its size. If you delete it, or comment it out, the table containing it will have blanks for non-zero points, and will align in the table with the original wave.
Note that the prior solution creates a new table every time it is called. This might cause some inconvenience, so I have omitted the 'Edit' command. Also, the prior solution might have a 0 at the 0'th point of the input wave, and then a trail of 0's at the end, possibly leading to further problems.
September 6, 2012 at 11:10 am - Permalink
it might be safer to use
to avoid floating point accuracy problems, where eps is a tolerance variable you define.
September 6, 2012 at 03:33 pm - Permalink