Remove blank rows from wave
Physicist92
Hi all,
Here is test function to generate wave with blank rows:
Function test1()
Make/O/D/N=(10,2) mywave=NaN
Variable i, j
for (i=0; i<10; i+=1)
for (j=0; j<2; j+=1)
if (mod(i,2)==0)
mywave[i][j] = 100+i+j
endif
endfor
endfor
End
Make/O/D/N=(10,2) mywave=NaN
Variable i, j
for (i=0; i<10; i+=1)
for (j=0; j<2; j+=1)
if (mod(i,2)==0)
mywave[i][j] = 100+i+j
endif
endfor
endfor
End
And here is the function that should remove blank rows from the wave:
Function remove_blank_rows(name_of_wave)
Wave name_of_wave
SumDimension/D=1/DEST=wout/Y=-1 name_of_wave
name_of_wave[][] = (NumType(wout[p]) == 2) ? NaN : name_of_wave[p][q]
SplitWave/N=Columns/SDIM=1 name_of_wave
String list = WaveList("Column*",";","")
String name
Variable numItems = ItemsInList(list)
Variable i
for (i=0; i<numItems; i+=1)
name = StringFromList(i,list)
Wave w = $name
WaveTransform zapNaNs w
endfor
Concatenate/O/KILL list, name_of_wave
End
Wave name_of_wave
SumDimension/D=1/DEST=wout/Y=-1 name_of_wave
name_of_wave[][] = (NumType(wout[p]) == 2) ? NaN : name_of_wave[p][q]
SplitWave/N=Columns/SDIM=1 name_of_wave
String list = WaveList("Column*",";","")
String name
Variable numItems = ItemsInList(list)
Variable i
for (i=0; i<numItems; i+=1)
name = StringFromList(i,list)
Wave w = $name
WaveTransform zapNaNs w
endfor
Concatenate/O/KILL list, name_of_wave
End
The problem is in the last line of the second function:
Concatenate/O/KILL list, name_of_wave
If I run:
remove_blank_rows(mywave)
Igor Pro writes the result into wave name_of_wave, but I'd like to write the result to existing wave mywave, thus to overwrite it. How should I change the function in order to make it write the result to existing wave mywave? Please find attached the wave mywave.
Forum
Support
Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More
You need to make a string of the name of the wave (which here is referenced as name_of_wave) and then use that with Concatenate. It's worth having a read about Wave Referencing.
Wave name_of_wave
String resultW = NameOfWave(name_of_wave)
SumDimension/D=1/DEST=wout/Y=-1 name_of_wave
name_of_wave[][] = (NumType(wout[p]) == 2) ? NaN : name_of_wave[p][q]
SplitWave/N=Columns/SDIM=1 name_of_wave
String list = WaveList("Column*",";","")
String name
Variable numItems = ItemsInList(list)
Variable i
for (i=0; i<numItems; i+=1)
name = StringFromList(i,list)
Wave w = $name
WaveTransform zapNaNs w
endfor
Concatenate/O/KILL list, $resultW
End
April 23, 2019 at 11:05 pm - Permalink
In reply to You need to make a string of… by sjr51
Thanks a lot!
April 24, 2019 at 03:26 am - Permalink
I think there is a simpler solution. Here is a test function generating more blank rows, with more columns
Make/O/D/N=(13,3) mywave=NaN
Variable i, j
for (i=0; i<13; i+=1)
for (j=0; j<3; j+=1)
if (mod(i,3)==0)
mywave[i][j] = 100+i+j
endif
endfor
endfor
End
and here is the gap (NaN) remover
No matter how many blank rows you start with, the re-dimensioned , zapped 1D wave will have a size divisable by the number of starting columns.
April 24, 2019 at 06:23 am - Permalink
In reply to I think there is a simpler… by s.r.chinn
Thanks a lot for your solution!
April 24, 2019 at 08:21 am - Permalink
s.r.chinn gave a better solution to your original problem, but if you wanted to use SplitWave like in your original question, you would be better off using the /OREF flag to make the output a wave reference wave. You could then run through that wave and zap the nans in the waves it contains, and then pass the wave reference wave as the input to Concatenate (assuming you're using Igor Pro 8).
April 24, 2019 at 08:30 am - Permalink
In reply to s.r.chinn gave a better… by aclight
I'm using Igor Pro 8. I will try to use /OREF flag. Thank you!
April 24, 2019 at 09:25 am - Permalink