Copying selected data from one wave into a new wave
john_crow
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!
Hope this helps.
// 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
February 19, 2014 at 01:48 am - Permalink
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.
February 19, 2014 at 02:03 am - Permalink
nWave = str2num(tWave[p])
where tWave is your text wave.
February 19, 2014 at 02:12 am - Permalink
"got 'tWave' instead of a string variable or string function name"
nWave = str2num(tWave[p])
February 19, 2014 at 02:30 am - Permalink
wave/T twave
variable threshold
Make/O/N=(numPnts(twave)) nwave
nwave = str2num(twave[p])
nwave = nwave>threshold ? nwave : NaN
WaveTransform zapNaNs nwave
end
February 19, 2014 at 02:51 am - Permalink
February 19, 2014 at 04:25 am - Permalink
// 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.
February 19, 2014 at 11:24 am - Permalink
February 19, 2014 at 11:11 pm - Permalink
hm, yes, shorter but not necessarily faster…well, at least not on large data sets ;-)
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
•speed1(test)
0.509921
•speed2(test)
1.08944
February 19, 2014 at 11:17 pm - Permalink