I have a bundle of text waves which have Nan values randomly. I want to delete these Nan points, but wavetranform's zapnans only support data wave. So any way to delete these points without using the "delete points" dialog?
You can't have NaNs in a textwave, so i'm assuming you mean empty strings.
Unfortunately, I don't think the conditional operator works on text waves so you'll have to write a little function that uses a for loop to evaluate each element in wave. Something like this should accomplish what you want
wave/t w variablei do if(strlen(w[i])==0) deletepointsi, 1, w endif i+=1 while(i<numpnts(w))
Without scripting as mentioned above the only way to do this is to edit them followed by selecting sections of empty cells and pressing Command/Control-X to cut them from the wave, though this is usually easiest for a smaller number of waves.
Depending on the nature of the text values in your wave (if they are numbers, as AG guessed), AG's solution may still be useful as str2num translates an empty string to NAN.
This is a function I am using to get rid of TRAILING Nans in TextWaves:
// Handy Function to delete trailing NaNs from TextWaves: Function DeleteNaNTextwave(W) Wave/T W Variablei=0, NOP Do
NOP = numpnts(W) if((strlen(W [i]) == 0)||(cmpstr("",W [i]) == 0)) DeletePointsi, 1, W i = 0// Start over again else i = i+1 endif while(strlen(w[NOP])==0) End
Unfortunately, I don't think the conditional operator works on text waves so you'll have to write a little function that uses a for loop to evaluate each element in wave. Something like this should accomplish what you want
variable i
do
if(strlen(w[i])==0)
deletepoints i, 1, w
endif
i+=1
while(i<numpnts(w))
March 26, 2013 at 03:14 pm - Permalink
then you can use the following function to clean them up:
Wave/T inWave
Make/Free/N=(numpnts(inWave)) tmp
tmp=str2num(inWave)
WaveTransform zapNaNs tmp
Make/o/T/N=(numpnts(tmp)) cleanText
cleanText=num2str(tmp)
End
If your waves contain something else then please give us more details.
A.G.
WaveMetrics, Inc.
March 26, 2013 at 03:17 pm - Permalink
March 26, 2013 at 04:04 pm - Permalink
March 27, 2013 at 07:30 am - Permalink
Depending on the nature of the text values in your wave (if they are numbers, as AG guessed), AG's solution may still be useful as str2num translates an empty string to NAN.
March 27, 2013 at 08:58 am - Permalink
Function DeleteNaNTextwave(W)
Wave /T W
Variable i=0, NOP
Do
NOP = numpnts(W)
if((strlen(W [i]) == 0)||(cmpstr("",W [i]) == 0))
DeletePoints i, 1, W
i = 0 // Start over again
else
i = i+1
endif
while(strlen(w[NOP])==0)
End
August 4, 2014 at 10:09 am - Permalink
Wave/T tw
Variable numPoints = numpnts(tw)
Variable i
for(i=numPoints-1; i>=0; i-=1)
if (strlen(tw[i]) == 0)
DeletePoints i, 1, tw
endif
endfor
End
August 5, 2014 at 01:11 am - Permalink