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
w[i][j]indexes rows and columns;pandqdo it in an assignment.MatrixOPruns a whole expression in one pass, in C.DimSize(w, 0)is the row count,DimSize(w, 1)the columns.
Keywords and builtins used here
DimSizeEndFunctionMakeMatrixOPPrintfVariableWAVEreturn
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.
Step 4 of 4 in Signals & matrices, step 14 of 16 in Waves & analysis.