typestar

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

  1. Sort key, w1, w2 reorders every wave by the same key.
  2. BinarySearch needs monotonic data and returns the point below.
  3. FindLevel finds where a wave crosses a value, in x units.

Keywords and builtins used here

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.

Type this snippet

Step 3 of 3 in Measuring, step 7 of 16 in Waves & analysis.

← Previous Next →

Sorting and searching in other languages