20 trials among the 150 rows in Excel

Win10 -version 2020.2.0 -Standard Standalone?y

I want participants to complete 20 random trials among the 150 rows in Excel. As long as I add an excel sheet to the loop, it runs all the rows in the sheet. How can I run 20 trials numbers by adding a code?

Since trials.thisN doesn’t work any more, you could set trialIdx=0 in a Begin Experiment code component tab and then add the following to the End Routine tab.

if trialIdx == 20:
1 Like

If you are running offline, then the most direct and explicit way to do this is to insert a Python expression in the “selected rows” field of your loop dialog:

$randchoice(150, size=20, replace=False)

If you are using an older version of PsychoPy, this function won’t be available to you by default and you will first need to insert a code component (from the “custom” component panel) and put this in the “Begin experiment” tab to give you access to it:

from numpy.random import choice

There in the “selected rows” field, put:

$choice(150, size=20, replace=False)


Thank you so much!