How to pass x array (along with some float variables) from Matlab to python, run definition, and return y array back to Matlab?
古いコメントを表示
Hello,
I have a complicated function that is defined in a python script that for inputs will take an x-array and several float variables and will return a y-array (same length as x-array). What I am looking to do is define all inputs in Matlab, call the python script from Matlab, and then have the output of the python script saved as an array in Matlab.
The python code I am looking to call is rather complicated (and the reason we don't want to translate it to Matlab), but a simple analogue for the procedure would be the following definition. The goal would be to define x, m, and b in Matlab, then call the python script containing the line definition, and return y so that it saved as a Matlab variable.
def line(m,b, x):
y = m*x + b
return y
I am not experienced in Matlab, so I wanted to reach out for some guidance. Any help would be greatly appreciated!
Thanks!
回答 (1 件)
Steven Lord
2018 年 2 月 27 日
0 投票
Are you using release R2014b or later? If so, see this section in the Release Notes. The links in the Release Notes go to the release R2014b documentation; if you're using a newer release, search for "Call Python Libraries" or "MATLAB Engine for Python" in your installation's documentation to find the version of those pages describing the functionality available in the release you're using.
カテゴリ
ヘルプ センター および File Exchange で Call Python from MATLAB についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!