Read variables from matlab

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,
Jing

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.

Chris

Attachment: server_side.zip (2.66 KB)

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

Jing