CallMATLAB从Python
Write Python®programs that work with MATLAB®
The MATLAB Engine API for Python provides a package for Python to call MATLAB as a computational engine. The engine supports the reference implementation (CPython).For supported version information, seeVersions of Python Compatible with MATLAB Products by Release.
To install and start the engine, see开始使用Python的Matlab Engine API.
To call Python functions from MATLAB, see从Matlab致电Python.
Engine applications require an installed version of MATLAB; you cannot run the MATLAB engine on a machine that only has the MATLAB Runtime.
fonctions
Classes
rubriques
Installing
- System Requirements for MATLAB Engine API for Python
您需要为Python编写和构建MATLAB引擎应用程序。 - Install MATLAB Engine API for Python
要在Python会话中启动MATLAB引擎,您首先必须将引擎API作为Python软件包安装。 - Install MATLAB Engine API for Python in Nondefault Locations
默认情况下,安装程序在python中构建引擎API
folder. If you install in another folder, update theMatlabroot
\extern\engines\pythonpythonpath
environment variable.
开始
- 开始使用Python的Matlab Engine API
The MATLAB Engine API for Python provides a Python package namedMATLAB
that enables you to call MATLAB functions from Python. - Start and Stop MATLAB Engine for Python
Options for starting the MATLAB Engine for Python. - 调用Python的MATLAB函数
How to return an output argument from a MATLAB function. How to read multiple outputs from a function. What to do when the MATLAB function does not return an output argument. - Get Help for MATLAB Functions from Python
From Python, you can access supporting documentation for all MATLAB functions.
会话管理
- Connect Python to Running MATLAB Session
如何将Python的MATLAB引擎连接到已经在本地计算机上运行的共享MATLAB会话。
Using MATLAB Workspace
- Use MATLAB Engine Workspace in Python
此示例显示了如何将变量添加到Python的MATLAB引擎工作区。
Data Exchange and Mapping
- Use MATLAB Arrays in Python
This example shows how to create a MATLAB array in Python and pass it as the input argument to the MATLABsqrt
function. - MATLAB阵列作为Python变量
TheMATLAB
Python模块提供数组类,以将MATLAB数字类型的数组表示为Python变量,以便可以在Python和Matlab之间传递MATLAB数组。 - Pass Data to MATLAB from Python
当您将Python数据作为输入参数传递给MATLAB函数时,用于Python的MATLAB引擎将数据转换为等效的MATLAB数据类型。 - Handle Data Returned from MATLAB to Python
当MATLAB函数返回输出参数时,Python的MATLAB引擎API将数据转换为等效的Python数据类型。 - Use MATLAB Handle Objects in Python
This example shows how to create an object from a MATLAB handle class and call its methods in Python. - MATLAB和PYTHON中的默认数字类型
MATLAB stores all numeric values as double-precision floating point numbers by default.
Calling MATLAB Functions
- 从Python调用用户脚本和函数
此示例显示了如何调用MATLAB脚本来计算Python的三角形区域。 - Sort and Plot MATLAB Data from Python
This example shows how to sort data about patients into lists of smokers and nonsmokers in Python and plot blood pressure readings for the patients with MATLAB. - Call MATLAB Functions Asynchronously from Python
This example shows how to call the MATLABsqrt
function asynchronously from Python and retrieve the square root later. - Redirect Standard Output and Error to Python
此示例显示了如何将标准输出和标准误差从MATLAB函数重定向到PythonStringio
objects.
résolutiondesproblèmes
The MATLAB Engine API does not support these features.
When a MATLAB function raises an error, the MATLAB Engine for Python stops the function and catches the exception raised by MATLAB.