Selecting different rows per iteration in a loop

I can think of two ways to do this.

Split up the conditions file

Advantage: easy to understand. Disadvantage: many conditions files.

In this case, you need two loops around your routine(s). The outer loop loops over a file with four rows, each containing a conditions file (say, in a column called conditions_file. The inner loop loads these conditions files in turn (enter $conditions_file as file name). So you have five conditions files in total: (1) row 1-12, (2) row 13-24, (3) row 25-36, (4) row 37-48, (5) the names of these four conditions files.

Select rows dynamically

Advantage: only one conditions file. Disadvantage: quite complex.

  1. Create a new routine with a code component in the beginning of your loop.
  2. Under “Begin experiment” define a variable: this_loop_number = 0.
  3. Then under “Begin Routine” increment this value on each loop: this_loop_number +=1.
  4. In the loop, set “select rows” to $((this_loop_number-1)*12+1):(this_loop_number*12)
  5. Finally, add a loop around the whole thing which repeats four times to get 1:12, 13:24, 25:36, and 37:48.
7 Likes