simple loop in a wave

hi,

i need to create a loop that goes to every point in a wave and compares every value of the wave to a threshold. my output should be how many data points of that wave go over that threshold.

example

threshold = 7

wave1
1
2
3
4
5
6
7
8
9

output = 2 // because 8 and 9 are over the threshold that is 7.

thanks,

carlos
make/n=10 junk=p
matrixop w=sumrows(greater(junk,7))
print w

print this in the history:

w[0]= {2}


You could also do this:

Duplicate junk, sumwave
sumwave = junk > 7 ? 1 : 0
print sum(sumwave)


and wrapping it in a function in Igor 6.2 allows you to use a free wave for the intermediate, eliminating the clutter:

Function countThreshold(w)
    Wave w
   
    duplicate/FREE w, sumwave
    sumwave = w > 7 ? 1 : 0
    return sum(sumwave)
end


My suspicion (without any testing) is that the matrixOP solution would be fastest if the input is very large.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
John's methods will be faster but here is a straightforward solution:

Function CountAboveThreshold(w, threshold)
    Wave w
    Variable threshold
   
    Variable count = 0
    Variable numPoints = numpnts(w)
    Variable i
    for(i=0; i<numPoints; i+=1)
        if (w[i] > threshold)
            count += 1
        endif  
    endfor
   
    return count
End


To learn about Igor Programming, execute this:
DisplayHelpTopic "Igor Pro Programming"

To add a third (or is it a forth?) solution:

Extract wave1, wave1_out, wave1>7
print numpnts(wave1_out)


or as a function:

Function countThreshold(w)
    Wave w
 
    extract/FREE w, extractedWave, w>7
    return numpnts(extractedWave)
end