0

When trying to build the most straightforward graph with weights on Matlab engine with Python -

s1 = ['a', 'b', 'c', 'd'];
t1 = ['b', 'c', 'd', 'e'];
w1 = [10, 20, 30, 40];
g = eng.graph(s1,t1,w1);

I'm getting this error:

MatlabExecutionError                      Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_15984/3466945527.py in 
      8 t1 = ['b', 'c', 'd', 'e'];
      9 w1 = [10, 20, 30, 40];
---> 10 g = eng.graph(s1,t1,w1);
     11 
     12 

c:\Users\user\anaconda3\lib\site-packages\matlab\engine\matlabengine.py in __call__(self, *args, **kwargs)
     68             return FutureResult(self._engine(), future, nargs, _stdout, _stderr, feval=True)
     69         else:
---> 70             return FutureResult(self._engine(), future, nargs, _stdout,
     71                                 _stderr, feval=True).result()
     72 

c:\Users\user\anaconda3\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):

c:\Users\user\anaconda3\lib\site-packages\matlab\engine\fevalfuture.py in result(self, timeout)
     80                 raise TimeoutError(pythonengine.getMessage('MatlabFunctionTimeout'))
...
  File C:\Program Files\MATLAB\R2022b\toolbox\matlab\graphfun\+matlab\+internal\+graph\constructFromEdgeList.m, line 256, in constructFromEdgeList

  File C:\Program Files\MATLAB\R2022b\toolbox\matlab\graphfun\@graph\graph.m, line 325, in graph.graph
Graph edge weights must be double or single, real, and not sparse

I tried to change the weight and ensure it was from double format, but nothing worked.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • What happens when you do this? `w1 = [10.0, 20.0, 30.0, 40.0];`. Also, can you provide a link to the `graph` function? – Mr Fooz Apr 08 '23 at 14:52
  • @MrFooz I tried it but it is still the same. Documentation here - https://www.mathworks.com/help/matlab/ref/graph.html – Amit Zeevi Apr 09 '23 at 13:42
  • What do `eng.disp(w1)` and `eng.disp(eng.class(w1))` say? I don't have Matlab anymore, so I can't test them myself. Also, try `w1 = end.double([10, 20, 30, 40])`. https://www.mathworks.com/help/matlab/matlab_external/use-matlab-arrays-in-python.html – Mr Fooz Apr 09 '23 at 14:13
  • `eng.disp(w1)` returns float. `eng.disp(eng.class(w1))` returns error. This - `w1 = end.double([10, 20, 30, 40])` doesn't work as well, and this `w1 = [eng.double(10), eng.double(20), eng.double(30), eng.double(40)]` return the original error :( – Amit Zeevi Apr 10 '23 at 12:11

0 Answers0