Easy way to mask waves?

It seems like there should be a really easy way to mask waves, but I haven't been able to figure one out so far. For example, I might have to waves of the same length and I would like to delete all the points from the first wave where the corresponding point on the second wave is zero. The way I've been doing this so far is embarrassingly hackey:

targetwave = targetwave/(maskwave==0) WaveTransform zapINFs targetwave WaveTransform zapNaNs targetwave // 0/0 = NaN

This has the obvious problem that it gets rid of any NaNs and INFs that should be in targetwave. What's the proper way to do this? Thanks

-Alex
Alex,

How about something like this?

Function DeletePointsInWave(w, wMask)
    Wave w         //wave to have points deleted
    Wave wMask     //comparison wave; zeroes here will delete corresponding points in w
 //w and wMask are assumed to be same length

    Variable vNumPoints
    Variable index
   
    vNumPoints = DimSize(w,0)
   
//have to do this from last point to first otherwise deleting points will change index of all points forward   
    for(index =  vNumPoints - 1; index >= 0; index -= 1)
        if(wMask[index] == 0)
            DeletePoints  index, 1, w
        endif
    endfor
End


My quick test shows that any point in wmask with a value of zero will cause the corresponding point in w to be deleted. There is no error checking, so watch out if it behaves unexpectedly. Hope this is what you have in mind.
Extract/O targetwave, targetwave, maskwave!=0 should also work. Be careful, targetwave is being overwritten! To avoid this, use a new name for destwave.
A
I'm trying something similar: I would like to use a piece of code that extracts a portion of a particular wave and use that portion to fill a new wave, rather than 'edit'-ing that wave and selecting the portion by mouse and ctrl+C&V. I would like to do something like the following:
Make /N=(pcsr(B)-pcsr(A)) copyWave
copyWave=sourceWave[pcsr(A):pcsr(B)]

however that does not work. What would be the proper code to do this?
skleijn wrote:
I'm trying something similar: I would like to use a piece of code that extracts a portion of a particular wave and use that portion to fill a new wave, rather than 'edit'-ing that wave and selecting the portion by mouse and ctrl+C&V. I would like to do something like the following:
Make /N=(pcsr(B)-pcsr(A)) copyWave
copyWave=sourceWave[pcsr(A):pcsr(B)]

however that does not work. What would be the proper code to do this?


Duplicate/R=[pcsr(A), pcsr(B)] sourceWave, copyWave