Matlab doesn't update when calling python API

1 次查看(过去 30 天)
David Haggerty
David Haggerty2021-5-17
回答: Pranjal Kaura ,2021-9-29
I am trying to implement a python API in MATLAB to read position data from a motion capture system for feedback control. The python API works in terminal perfectly, but when I try to call it in MATLAB the position fails to update, which means to me there is something about how MATLAB calls python functions that is static (which is supported by the fact that when I update the python code, I need to restart MATLAB for the changes to take effect). Is there a workaround for this? Or some coder settings that I can tweak?
My code is supplied below:
The API call is simply
dataTest = py.mocapPosition.readSys;
And the python code is
import owlXYZ
import sys
o = owlXYZ.Context()
# connect to server with timeout of 10000000 microseconds, "timeout=100000")
# initialize session
def readSys():
evt = o.nextEvent(100)
newlist = []
while evt.type_id != owlXYZ.Type.FRAME:
evt = o.nextEvent(100)
if "markers" in evt:
for m in evt.markers:
return newlist
elif evt.type_id == owlXYZ.Type.ERROR:
elif == "done":
# done event is sent when master connection stops session
# end main loop
def close():
# end session
# close socket
The header file owlXYZ supplies all the declarations necessary to import data from the server. All help is appreciated!

回答(1 个)

Pranjal Kaura
Pranjal Kaura 2021-9-29
Hey David,
You could go through the following documentations, to know more about reloading python interpreter from MATLAB. This will help you update the modified module files(python) in MATLAB.
A workaround could be to output the position matrix from python to MATLAB using the 'pyrunfile' command and then using it in your feedback control model.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by