1

我有一个 CSV 文件,如下所示:

cond, arg
T, arg1 
T, arg2
T, arg3
T, arg4
T, arg5
P, arg6
P, arg7
P, arg8
P, arg9
P, arg10

现在我可以从“arg”列中获取随机值,只需将值“$arg”放入“Text element”</p>

我的问题是,仅通过使用“构建器视图”,例如“文本元素”和“代码元素”,是否可以随机获取属于满足条件 $cond='P' 的行的值?

4

1 回答 1

2

I would suggest that the easiest way to do this in Builder would be to split your CSV file into two separate files (in this case, one containing "arg1"-"arg5" and the other containing "arg6"-"arg10"), named, say, T.csv and P.csv.

Then in your loop, instead of having a hard-coded conditions filename, like "conditions.csv", put a variable name, like "$conditionFilename" (without the quotes). You then just need a way to specify the value of that variable before the loop gets created. e.g. Let's say you add a field called "conditionType" to the Experiment Settings dialog which the experimenter will set before each run, which will contain the values "P" or "T". Then in a code component, in the "Begin Experiment" tab, put something like this:

if expInfo['conditionType'] == 'P':
    conditionFilename = 'P.csv'
else:
    conditionFilename = 'T.csv'

Set the loop to be random, and you will get random selection within those particular trials. I think the conditionType variable will be automatically stored in your data along with the other experiment settings.

于 2014-08-12T23:58:57.573 回答