numpy to matlab interface with mlabwrap
Asked Answered
C

2

6

I am looking for a simple way to visualize some of my data in numpy, and I discovered the mlabwrap package which looks really promising. I am trying to create a simple plot with the ability to be updated as the data changes.

Here is the matlab code that I am trying to duplicate

>> h = plot([1,2,3], [1,2,3], '-o');
>> set(h, 'XData', [0,0,0]);
>> drawnow();

to python

>> from mlabwrap import mlab
>> h = mlab.plot([1,2,3], [1,2,3], '-o')
>> mlab.set(h, 'XData', [0,0,0])
>> mlab.drawnow();

However, the second to last command fails with an error message

error: One or more output arguments not assigned during call to "set".

Any suggestions on how to fix this?

Concavoconvex answered 20/12, 2009 at 3:25 Comment(0)
J
6

Maybe mlab is mad that you're not saving matlab's return value for that set() call...

I don't have this installed, what does someval = mlab.set(h,'XData') give?

edit: you could also try using nout... mlab.set(h,'XData',[0,0,0],nout=0)

Jessjessa answered 20/12, 2009 at 4:16 Comment(1)
Thanks, you bet me to the answer by a few minutes. By default, mlabwrap translates the python command to [RES0__]=set(arg0__, arg1__, arg2__);, and since set takes no ouptut arguments, this results in the error above.Concavoconvex
C
5

Since set takes no output arguments, we need to tell mlabwrap that no output arguments should be given to it to avoid the error message above.

mlab.set(h, 'XData', [0,0,0], nout=0)
Concavoconvex answered 20/12, 2009 at 4:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.