Sorting and searching in Igor Pro
Sort reorders in place; the search functions expect an ordered wave.
Function FindCrossing(WAVE times, WAVE values, Variable level)
Sort times, times, values
FindLevel/Q values, level
if (V_flag != 0)
return NaN
endif
Variable index = BinarySearch(times, V_LevelX)
Printf "crossed %g at x=%g (point %d)\r", level, V_LevelX, index
return V_LevelX
End
How it works
Sort key, w1, w2reorders every wave by the same key.BinarySearchneeds monotonic data and returns the point below.FindLevelfinds where a wave crosses a value, in x units.
Keywords and builtins used here
BinarySearchEndFindLevelFunctionNaNPrintfSortVariableWAVEendififreturn
The run, in numbers
- Lines
- 12
- Characters to type
- 282
- Tokens
- 52
- Three-star pace
- 80 tpm
At the three-star pace of 80 tokens a minute, this run takes about 39 seconds.
Step 3 of 3 in Measuring, step 7 of 16 in Waves & analysis.