Is there a clean way to remove repeating values from waves? I have waves that sometimes have duplicates or triplicates of a number and I would like to keep only one instance. I have looked in the forum and manual but I haven't spotted anything like a function that may help in doing this. I was thinking of sorting and creating two lists to move numbers from one to the other after parsing through but any ideas are appreciated.
Just for clarification: You want unique INTEGERS in the wave (and not just zap consecutive occurrences)?
Maybe this could serve as a first idea (result is sorted):
make/N=6 test ={1,1,3,4,4,1} make/N=10 hist // Probably needs to be adjusted to the minimum and maximum values of the wave histogram/B={0,1,10} test, hist // here as well
hist= (hist==0) ? nan : p wavetransform ZapNaNs hist
Here is my take on it. Zaps all repeating integers after the first one.
Invoke it like: thunk_zapnum(w_wave, 5)
The code is limited to Integer values and you would have to loop over a list of integers which you want to remove.
If you just wanted to remove a specific value from a wave it is simpler to execute:
MatrixOP/O aa=replace(w_wave,specificValue,NaN) WaveTransform zapNaNs aa
Note that in this example specificValue is any real-value and strict equality is required, something that FindDuplicates handles via the Tolerance flag.
MatrixOP/O aa=replace(w_wave,specificValue,NaN) WaveTransform zapNaNs aa
..
A.G.
This will also remove the first instance of the duplicate integer, which I interpreted as a requirement of the poster. If this isn't the case, then, indeed, there is no need for looping through the indeces of the duplicate integer.
This will also remove the first instance of the duplicate integer, which I interpreted as a requirement of the poster. If this isn't the case, then, indeed, there is no need for looping through the indeces of the duplicate integer.
_sk
You are absolutely right. It will remove all instances.
Maybe this could serve as a first idea (result is sorted):
make /N=10 hist // Probably needs to be adjusted to the minimum and maximum values of the wave
histogram /B={0,1,10} test, hist // here as well
hist= (hist==0) ? nan : p
wavetransform ZapNaNs hist
Beware of floats !
HJ
August 22, 2017 at 03:00 pm - Permalink
A.G.
WaveMetrics, Inc.
August 22, 2017 at 03:41 pm - Permalink
August 22, 2017 at 06:09 pm - Permalink
Invoke it like:
thunk_zapnum(w_wave, 5)
, wherew_wave
is your wave,5
is the number you want to zap.wave& w_wave //1d wave
variable v_num
variable i
variable v_sz = dimsize(w_wave,0)
make/o/n=(v_sz) w_ind = (w_wave == v_num) ? p : nan
wavetransform/o zapnans, w_ind
variable v_sz_ind = dimsize(w_ind,0)
for (i=1; i<v_sz_ind; i+=1)
w_wave[w_ind[i]] = nan
endfor
wavetransform/o zapnans, w_wave
end
best,
_sk
August 23, 2017 at 01:17 am - Permalink
The code is limited to Integer values and you would have to loop over a list of integers which you want to remove.
If you just wanted to remove a specific value from a wave it is simpler to execute:
WaveTransform zapNaNs aa
Note that in this example specificValue is any real-value and strict equality is required, something that FindDuplicates handles via the Tolerance flag.
A.G.
August 23, 2017 at 10:59 am - Permalink
This will also remove the first instance of the duplicate integer, which I interpreted as a requirement of the poster. If this isn't the case, then, indeed, there is no need for looping through the indeces of the duplicate integer.
best,
_sk
August 23, 2017 at 12:41 pm - Permalink
You are absolutely right. It will remove all instances.
August 23, 2017 at 05:51 pm - Permalink