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.