typestar

Two-dimensional waves in Igor Pro

A matrix is a wave with two dimensions, and MatrixOP is the fast way through one.

Function/WAVE ColumnMeans(WAVE m)
    Variable rows = DimSize(m, 0), cols = DimSize(m, 1)

    Make/O/N=(cols)/D means
    MatrixOP/O means = sumCols(m) / rows

    Make/O/N=(rows, cols)/D centered
    centered = m[p][q] - means[q]

    Printf "%d by %d, centered\r", rows, cols
    return means
End

How it works

  1. w[i][j] indexes rows and columns; p and q do it in an assignment.
  2. MatrixOP runs a whole expression in one pass, in C.
  3. DimSize(w, 0) is the row count, DimSize(w, 1) the columns.

Keywords and builtins used here

The run, in numbers

Lines
12
Characters to type
271
Tokens
78
Three-star pace
85 tpm

At the three-star pace of 85 tokens a minute, this run takes about 55 seconds.

Type this snippet

Step 4 of 4 in Signals & matrices, step 14 of 16 in Waves & analysis.

← Previous Next →