read variables from matlab

wangjing's Avatar


16 Aug, 2018 04:44 PM

Dear Chris,
I have a motion tracking script running outside Mworks, Is it possible to read the value (animal's position as x, y) in Matlab or Python, and update the variables in Mworks when change happens? Any suggestion would be helpful. Thanks,

  1. Support Staff 1 Posted by Christopher Sta... on 17 Aug, 2018 05:44 PM

    Christopher Stawarz's Avatar

    Hi Jing,

    It's possible to set MWorks variables from a Python script (but not from MATLAB).

    The easiest method is to run your script inside MWServer via the run_python_file and run_python_string actions. From within your script, you can use the getvar and setvar functions to read and write MWorks variables.

    Alternatively, if you need to run your code outside of MWServer, you can use a server-side conduit. I've attached an example that demonstrates how to set this up. To run it, first load the experiment, then launch the Python script (e.g. from a Terminal window). The script updates the variable myvar every five seconds. You should see the updates reported in the server console.

    If you have any questions, please let me know.


  2. 2 Posted by wangjing on 17 Aug, 2018 06:44 PM

    wangjing's Avatar

    Hi Chris, that's great! thank you very much.


  3. Christopher Stawarz closed this discussion on 22 Aug, 2018 06:29 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac