How can I convert Python list to column vector?
Show older comments
I'm using the fitdist method from MATLAB in Python where x is:

I tried different approaches to work on this and they all give the same error:
eng.fitdist(eng.cell2mat(list(x)), 'stable')
eng.fitdist(matlab.double(list(x)), 'stable')
eng.fitdist(list(x), 'stable')
All of these give me this error:
MatlabExecutionError:
File C:\Program Files\MATLAB\R2020b\toolbox\stats\stats\fitdist.m, line 126, in fitdist X must be a numeric column vector.
Any idea how to get out of it? How do I convert my list to a column vector that works with MATLAB?
I am using MATLAB R2020b
Accepted Answer
More Answers (1)
Raynier Suresh
on 22 Feb 2021
Hi, The input to fitdist must be a column vector, from your image it looks like the input has multiple columns in it. You can pass the list with single column to matlab.double() and then pass it to the fitdist function. You can refer the below code and links for more information.
from sklearn import datasets
import matlab.engine
eng = matlab.engine.start_matlab()
iris = datasets.load_iris()
X = iris.data[:, :1]
print(X)
L = X.tolist()
print(L)
Pd = eng.fitdist(matlab.double(L),'stable')
print(Pd)
1 Comment
Natali Ayoub
on 24 Feb 2021
Categories
Find more on Call MATLAB from Python in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!