Question on the selection matrix

Good morning Chris,

We now have a protocol with two different types of trials. So we are wondering if there is a way to have two selection matrices in one protocol and have them being picked separately for the two types of trials?

I’ve attached the matrix_select.mwel below. It seems like we will need two new variables for current_selection and selection_matrix?

Best,
Taylor

import random
from mworkscore import getvar, setvar, message

command = getvar('command')
current_selection = getvar('current_selection')
selection_matrix = getvar('selection_matrix')

if ((command == 'start') or (command == 'reset')):
    matrix = getvar('matrix')
    selection_matrix = matrix
elif command == 'accept':
    if (len(selection_matrix) > 0):
        selection_matrix.remove(selection_matrix[current_selection])
if len(selection_matrix) > 1:
    current_selection = random.randint(0,len(selection_matrix)-1)
elif (len(selection_matrix) == 1):
    current_selection = 0

setvar('selection_matrix', selection_matrix)
setvar('current_selection', current_selection)

Hi Taylor,

Yes, adding two additional MWorks variables (e.g. selection_matrix_2, current_selection_2) is one option.

Another option would be to change the existing variables into lists, with each element being either the selection matrix or the current selection for a given trial type. In other words, instead of

var current_selection = 0
var selection_matrix = [[0,0],[0,0]]

you would have

var current_selection = [0, 0]
var selection_matrix = [[[0, 0], [0, 0]], [[0, 0], [0, 0]]]

Then, when operating on the selection matrix, you would need to specify the index corresponding to the relevant trial type. Alternatively, you could define the variables as dictionaries, rather than lists, and use strings (or arbitrary integers) as keys to identify the trial type. Are you already storing the selected trial type in a variable? If so, what are its possible values?

Either option would work, although the second approach would more readily handle a further increase in the number of trial types. Does one of the options sound better to you? I can write some Python code demonstrating how things would work in more detail, if that would help.

Cheers,
Chris

Hi Chris,

I think the second way is more elegant and should work. I will try it tomorrow and get back to you. Thank you!

Best,
Taylor