Copying selected data from one wave into a new wave

Hi, new user here.

I have a wave with one column of numbers. I want to select all of the numbers in the wave greater than say, x, and copy them in to a new wave.

I'm basically completely lost. Thanks for your help!
Here is one way of doing it.
Hope this helps.

Function Test()
	// make some test data
	Make/O/N=10 wData={5,3,4,5,6,2,1,7,0,9}
	// copy to a 'result' wave
	Duplicate/O wData,wFilteredData
	// use conditional to set certain values to NaN
	wFilteredData[] = wFilteredData[p]>5 ? wFilteredData[p] : NaN
	// remove the NaNs
	WaveTransform zapNaNs wFilteredData
	// display the data in a table
	Edit wData,wFilteredData
End
Thanks for replying. I tried your suggestion and got this message:
An attempt was made to treat a text wave as if it were a numeric wave.

I didn't think I had a text wave... The example with your wData wave works though.
you can convert your data:


Make/N = (numpnts(tWave)) nWave
nWave = str2num(tWave[p])


where tWave is your text wave.
Sorry for all the questions but when I try to compile I get an error saying:

"got 'tWave' instead of a string variable or string function name"
nWave = str2num(tWave[p])
In a function you need to tell Igor that the text wave is a text wave. Try this:


function convert(tWave, threshold)
	wave/T twave
	variable threshold
	
	Make/O/N=(numPnts(twave)) nwave
	nwave = str2num(twave[p])
	
	nwave = nwave>threshold ? nwave : NaN
	WaveTransform zapNaNs nwave	
end
Guys, guys!


Function Test()
	// make some test data
	Make/O/N=10 wData={5,3,4,5,6,2,1,7,0,9}
	// extract values > 5
	Extract wData, wFilteredData, wData > 5
	// display the data in a table
	Edit wData,wFilteredData
End


--Jim Prouty
Software Engineer, WaveMetrics, Inc.
JimProuty wrote: Guys, guys!


Function Test()
	// make some test data
	Make/O/N=10 wData={5,3,4,5,6,2,1,7,0,9}
	// extract values > 5
	Extract wData, wFilteredData, wData > 5
	// display the data in a table
	Edit wData,wFilteredData
End



hm, yes, shorter but not necessarily faster…well, at least not on large data sets ;-)


function speed1(w)
	wave w
	variable num = StartmsTimer 
	
	Duplicate/O w nw
	Multithread nw = w > 3 ? w : NaN
	Wavetransform zapNaNs nw
	print Stopmstimer(num)/1e6
end

function speed2(w)
	wave w
	variable num = StartmsTimer 
	
	Extract/O w, nw, w > 3
	print Stopmstimer(num)/1e6
end



•make/N=1e7 test = enoise(5)
•speed1(test)
  0.509921
•speed2(test)
  1.08944