1

I am working on a Python script in which I have to call some Matlab Psychtoolbox functions to open a screen window and display a dot. I am trying to use the Matlab Engine API for Python: when running the code I get a MatlabExecutionError: Usage: for the eng.Screen('Preference', 'SkipSyncTests', 1) line. My code is the following:

import matlab.engine
import numpy as np

eng = matlab.engine.start_matlab()
screens = eng.Screen('Screens');
screenNumber =np.amax(screens);

eng.Screen('Preference', 'SkipSyncTests', 1)
[w,wrect]=eng.Screen('OpenWindow',0) ; # open PTB window

eng.Screen('FillOval',w,[1.0,1.0,1.0],[0,0]); # draw fixation dot (flip erases it)

eng.Screen('Flip',w); # draw image
eng.KbStrokeWait;

eng.Screen('CloseAll')
eng.quit()

The error reads:

---------------------------------------------------------------------------
MatlabExecutionError                      Traceback (most recent call last)
<ipython-input-2-9907084f81ad> in <module>()
      9 
     10 
---> 11 q=eng.Screen('Preference', 'SkipSyncTests', 1)         ; # do not test for accurate timing
     12 
     13 

~\AppData\Local\Programs\Python\Python36\lib\site-packages\matlab\engine\matlabengine.py in __call__(self, *args, **kwargs)
     69         else:
     70             return FutureResult(self._engine(), future, nargs, _stdout,
---> 71                                 _stderr, feval=True).result()
     72 
     73     def __validate_engine(self):

~\AppData\Local\Programs\Python\Python36\lib\site-packages\matlab\engine\futureresult.py in result(self, timeout)
     65                 raise TypeError(pythonengine.getMessage('TimeoutCannotBeNegative'))
     66 
---> 67         return self.__future.result(timeout)
     68 
     69     def cancel(self):

~\AppData\Local\Programs\Python\Python36\lib\site-packages\matlab\engine\fevalfuture.py in result(self, timeout)
     80                 raise TimeoutError(pythonengine.getMessage('MatlabFunctionTimeout'))
     81 
---> 82             self._result = pythonengine.getFEvalResult(self._future,self._nargout, None, out=self._out, err=self._err)
     83             self._retrieved = True
     84             return self._result

MatlabExecutionError: Usage:

oldPreferenceValue = Screen('Preference', preferenceName, [newPreferenceValue])

I expected a Psychtoolbox window to appear from my matlab application, but instead this error shows. I also tried erasing the eng.Screen('Preference', 'SkipSyncTests', 1) line, however the same type of error is given then by the [w,wrect]=eng.Screen('OpenWindow',0) line. Is this an engine API error? Or am I calling the functions in a wrong syntax for the Engine API?

mordecai9
  • 11
  • 2

0 Answers0