MATLAB python binding: Undefined function 'isfinite' for input arguments of type 'cell'

Viewed 85

I am trying to compute numerically the roots of a polynomial by calling into MATLAB from Python.

Here is a MWE:

import matlab.engine

matlab_eng = matlab.engine.start_matlab()
poly = [4,1]
print(matlab_eng.roots(poly))

I consistently get the following error:

Check for incorrect argument data type or missing argument in call to function 'isfinite'.

Error in roots (line 26)
if ~all(isfinite(c))

Traceback (most recent call last):
  File "/home/alex/src/riley/test.py", line 5, in <module>
    print(matlab_eng.roots(poly))
  File "/usr/lib/python3.9/site-packages/matlab/engine/matlabengine.py", line 70, in __call__
    return FutureResult(self._engine(), future, nargs, _stdout,
  File "/usr/lib/python3.9/site-packages/matlab/engine/futureresult.py", line 67, in result
    return self.__future.result(timeout)
  File "/usr/lib/python3.9/site-packages/matlab/engine/fevalfuture.py", line 82, in result
    self._result = pythonengine.getFEvalResult(self._future,self._nargout, None, out=self._out, err=self._err)
matlab.engine.MatlabExecutionError: 
  File /home/alex/MATLAB/R2021b/toolbox/matlab/polyfun/roots.m, line 26, in roots
Undefined function 'isfinite' for input arguments of type 'cell'.

I have MATLAB R2021b and Python 3.9.7.

It looks like everything is being wrapped up in future objects by the Python bindings and then passed into roots(), but the latter can't accept that. Is this a problem with MATLAB which I need to find a workaround for, or is it an error in my code?

0 Answers
Related