Remove blank rows from wave

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

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

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.

mywave

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.

Function remove_blank_rows(name_of_wave)
    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

 

I think there is a simpler solution. Here  is a test function generating more blank rows, with more columns

Function test1()
    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

Function remove_blank_rows(inwave)
	wave inwave

	variable nrows = dimsize(inwave,0)  // includes NaN rows
	variable ncols = dimsize(inwave,1)
	Redimension /N=(nrows*ncols) inwave
	WaveTransform zapNaNs  inwave
	variable nrows2 = numpnts(inwave)/ncols // always divisable by ncols
	Redimension /N=(nrows2, ncols) inwave
end

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.

In reply to by s.r.chinn

s.r.chinn wrote:

I think there is a simpler solution. Here  is a test function generating more blank rows, with more columns

Function test1()
    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

Function remove_blank_rows(inwave)
	wave inwave

	variable nrows = dimsize(inwave,0)  // includes NaN rows
	variable ncols = dimsize(inwave,1)
	Redimension /N=(nrows*ncols) inwave
	WaveTransform zapNaNs  inwave
	variable nrows2 = numpnts(inwave)/ncols // always divisable by ncols
	Redimension /N=(nrows2, ncols) inwave
end

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.

Thanks a lot for your solution!

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).

In reply to by aclight

aclight wrote:

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).

I'm using Igor Pro 8. I will try to use /OREF flag. Thank you!

Forum

Support

Gallery

Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More