Hi Mark,
Many variables generate events only when their value is changed. However, we would like, when start is pressed in MWClient, to generate an event for every variable checked in the Events box. From then on, an event should be generated only when changed. That allows us to record the value of every variable as trials begin.
Is this the current behavior of the matlab bridge?
No. MWorks does announce all variable values when the experiment starts, and these values are recorded in the event file (if one is open). However, the MATLAB window isn’t really set up to catch these announcements.
Does your experiment explicitly set the values of all relevant variables at the start of the trial, or does it rely on the defaults set via the default_value
parameter? If the former, then you could just sandwich the variable initializations between sync=1 and sync=0:
// Init vars
sync = 1
var_a = 3
var_b = 4
...
sync = 0
// Begin trial
...
If you’re relying on default_value
, then you could use the same basic approach, except that you’d assign each variable to itself:
// Announce vars
sync = 1
var_a = var_a
var_b = var_b
...
sync = 0
// Begin trial
...
A bit of Python can make this process more robust and automatic. For example, if announce.py
contains:
def announce_vars():
for name in get_reverse_codec():
setvar(name, getvar(name))
and your experiment includes it as a Python file resource:
python_file ('announce.py')
then the following three lines will announce every variable in the experiment such that the MATLAB window can record their values:
sync = 1
run_python_string ('announce_vars()')
sync = 0
I think that’s probably the best you can do with the current MATLAB window. Things would be simpler with a Python bridge script, as event handlers you register there will execute whenever variable values are announced, including when the experiment starts. Server-side Python actions are even more flexible, as you can grab the current value of any variable at any time with getvar
. But if you want to use the MATLAB window, then I think you’re stuck with one of the above solutions.
Chris