Skip to content
Indices & Loops

Indices & Loops

Every variable reference in Frida carries up to three optional indices: [k, j, i] for file, spectrum, and data point. When indices are omitted, Frida fills them from the current context.

Index notation

y[k, j, i]    # fully explicit
y[k]          # y[k, j, i] — j and i from context
y[k, j]       # y[k, j, i] — i from context
y[, j]        # y[k, j, i] — k and i from context
y[,, i]       # y[k, j, i] — k and j from context

Plain y means y[k, j, i] with all three from context.

The same notation applies to x, dy, z0, p0, r0, etc.

Running variables

Variable Role
k file (workspace) number
j spectrum index within file
i data-point index within spectrum

How Frida loops

Each command implicitly loops over a subset of k, j, i depending on the operation:

Command Loops over
oy <expr> all j and all i in each selected file
oz0 <expr>, op2 <expr> all j only (one value per spectrum)
oi (rank-reducing) all j (one result per spectrum)
file-range prefix (e.g. 3-5) k = 3, 4, 5

Example — display one value across three files:

3-5 > . y[,0,3]

prints y[k, 0, 3] for k = 3, 4, 5.

Example — set curve data-file references in a loop:

? > 10:13 cd k-8

sets curve file 10 to fit data file 2, curve 11 → data file 3, etc.

Example — set all y values to x²:

4 > oy x^2

executes y[k,j,i] := x[k,j,i]^2 for every spectrum j and point i in file 4.

Cross-workspace arithmetic

Because indices can reference any file, expressions can combine data from multiple workspaces in a single command.

Subtract an empty-cell measurement

Workspace 4 holds an empty-cell measurement. Subtract it from workspaces 0–3:

0-3 > oy y-y[4]

y[4] means y[4, j, i] — the same spectrum j and point i as the target, but from file 4. Frida writes results to new workspaces (the originals are preserved).

Normalize by per-spectrum integrated intensity

Run oi (option 9, sum) on the data, giving workspace 5 with one integrated intensity per spectrum (ni = 1). Then normalize:

0-4 > oy y/y[5, 0, j]

y[5, 0, j] — workspace 5, energy channel 0, spectrum j — picks the correct integrated intensity for each spectrum. Use df to verify what occupies each index position before writing such expressions.

Initialize fit parameters from another file

File 4 holds previously fitted peak positions as a function of z0. Use them as starting values for p1 in file 5:

5 > op1 y[4, 0, j]