Extract data from a wave based on changes in its value

I have a wave that has repeated blocks of data that is non-zero and zero. Each repeated set of non-zero data is identified with a unique batch experiment. However, the batch experiment doesn't have unique identifier. The only identifier between the two batch experiment data is that presence of a block of zeros. Also, each set of non-zero data has non-fixed number of points. I want extract each set of non-zero data from the wave and perform data analysis on that which will be exclusive to that particular batch experiment.

I think or thought it would be a fairly easy exercise, but I think it's not (for me). I am still at a beginner level in Igor.

Test data (45 KB)

Hi,

 

So thoughts and questions:

Looking at your data it seems to increase and then go back to zero between runs. So is zero unique to the period between runs or could your data span zero (go from positive to negative). If it is always positive except for zero, then you could use findlevels function 

findlevels /edge=1 columna 0.01

which looks for crossing 0.01 but only in the positive direction.  This produces a wave with the points

144.0006896551724
284.0008695652174
438.0006896551724

You would could do a round or floor on those values and I would insert the value 0 in the beginning.

If the real data is more complex and can go negative, I might think about a derivative and look for consistent zero slopes.  You could use findlevels again but without the direction constraint, but add the /M flag to specify a minimum number of points that need to be seen at that level.

Andy
 

There will be many ways to do this.

Here is one possibility that uses extract to find the indices of the start and end points:

function ExtractBlocks(wave w)
    Extract/INDX w, startPoints, (p==0 || w[p-1]==0) && w[p]!=0
    Extract/INDX w, endPoints, (p==(numpnts(w)-1) || w[p+1]==0) && w[p]!=0
    variable i
    for(i=0;i<numpnts(startPoints);i++)
        Duplicate/R=[startPoints[i],endPoints[i]] w $NameOfWave(w)+num2str(i)
    endfor
end