Matlab bridge: event stream for non-changing values

Hi Chris,

I have a question about the intended behavior of the Matlab bridge.
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?
Where does that variable event dump occur in the trial start process?
Does it depend on where the first sync=1 setting is in the experiment?

Thanks,
Mark

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

Hi Chris,

We have noticed that if we press start, then stop, then start (with a ~1s delay between presses), each variable value is announced and passed to the Matlab bridge.

Is this a bug? (If so, please don’t fix it until we’ve had a chance to fix our experiments!).

Based on what you’ve said, my guess is that what’s happening with start, stop, start is this:

  1. Experiment starts. Actions happen. One of them is sync=1.
  2. Experiment is stopped without completing a trial. Sync is still 1.
  3. Experiment starts again. All variable values are announced. But sync is still 1, so they get sent down the event stream to the Matlab window. At end of first trial, sync is 0 and events from both the truncated and complete trial get sent.

Is that plausible? (If so it finally gives an explanation for an effect that’s long been mysterious.)

Mark

Hi Mark,

Is that plausible?

Yes, I suspect that’s exactly what’s happening. I don’t think I’d call it a bug, but it does seem like the MATLAB window could do a better job of handling that scenario. On other hand, if the current behavior is useful to you, then we could just leave it as is.

Chris