How to pass x array (along with some float variables) from Matlab to python, run definition, and return y array back to Matlab?
Show older comments
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!
Answers (1)
Steven Lord
on 27 Feb 2018
0 votes
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.
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!