simple loop in a wave
carlosgarzonc
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
matrixop w=sumrows(greater(junk,7))
print w
print this in the history:
w[0]= {2}
You could also do this:
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:
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
August 17, 2010 at 08:50 am - Permalink
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:
August 17, 2010 at 09:26 am - Permalink
print numpnts(wave1_out)
or as a function:
Wave w
extract/FREE w, extractedWave, w>7
return numpnts(extractedWave)
end
August 17, 2010 at 09:52 pm - Permalink