# MATLAB Engine API for Python
The MATLAB® Engine API for Python® provides a package to integrate MATLAB functionality directly with a Python application, creating an interface to call functions from your MATLAB installation from Python code.
---
## Requirements
### Required MathWorks Products
<!-- MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string) -->
* MATLAB release R2023a
### Required 3rd Party Products
<!-- MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string) -->
* Python 3.8, 3.9, or 3.10
* Supported Python versions by MATLAB release can be found [here](https://www.mathworks.com/support/requirements/python-compatibility.html).
---
## Install
### Windows
MATLAB Engine API for Python can be installed directly from the Python Package Index.
<!-- MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string) -->
```bash
$ python -m pip install matlabengine==9.14.3
```
### Linux®
Prior to installation, check the default install location of MATLAB by calling ```matlabroot``` in a MATLAB Command Window. By default, Linux installs MATLAB at:<br>
<!-- MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string) -->
```/usr/local/MATLAB/R2023a```
When MATLAB is not installed in the default location, the bin/*architecture* directory within the MATLAB root directory must be added to an environment variable. The path can be added to the environment variable within the shell startup configuration file (for example, .bashrc for bash shell or .tcshrc for tcsh).
```bash
# in .bashrc
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<matlabroot>/bin/glnxa64
```
```bash
# in .tcshrc
setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:<matlabroot>/bin/glnxa64
```
MATLAB Engine API for Python can be installed directly from the Python Package Index.
<!-- MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string) -->
```bash
$ python -m pip install matlabengine==9.14.3
```
### macOS
Prior to installation, check the default install location of MATLAB by calling ```matlabroot``` in a MATLAB Command Window. By default, macOS installs MATLAB at:<br>
<!-- MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string) -->
```/Applications/MATLAB_R2023a.app```
When MATLAB is not installed in the default location, the bin/*architecture* directory within the MATLAB root directory must be added to an environment variable. The path can be added to the environment variable within the shell startup configuration file (for example, .bashrc for bash shell or .tcshrc for tcsh).
```bash
# in .bashrc
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:<matlabroot>/bin/maci64
```
```bash
# in .tcshrc
setenv DYLD_LIBRARY_PATH ${DYLD_LIBRARY_PATH}:<matlabroot>/bin/maci64
```
MATLAB Engine API for Python can be installed directly from the Python Package Index.
<!-- MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string) -->
```bash
$ python -m pip install matlabengine==9.14.3
```
---
## Getting Started
* Start Python.
* Import the ```matlab.engine``` package into the Python session.
* Start a new MATLAB process by calling ```start_matlab```. The ```start_matlab``` function returns a Python object which enables you to pass data and call functions executed by MATLAB.
```python
>>> import matlab.engine
>>> eng = matlab.engine.start_matlab()
>>> eng.sqrt(4.0)
2.0
```
* Call either the ```exit``` or ```quit``` function to stop the engine. Exiting Python with an engine running stops the engine and its MATLAB processes.
```python
>>> eng.quit()
```
See [Start and Stop MATLAB Engine for Python](https://www.mathworks.com/help/matlab/matlab_external/start-the-matlab-engine-for-python.html) for advanced startup examples.
---
## Examples
You can call any MATLAB function directly and return the results to Python.
```python
>>> eng.plus(2, 3)
5
>>> eng.isprime(37)
True
>>> eng.gcd(100.0, 80.0, nargout=3)
(20.0, 1.0, -1.0)
```
See [Call MATLAB Functions from Python](https://www.mathworks.com/help/matlab/matlab_external/call-matlab-functions-from-python.html) for more usage examples.
---
## Limitations
Limitations of the MATLAB Engine API for Python can be found [here](https://www.mathworks.com/help/matlab/matlab_external/limitations-to-the-matlab-engine-for-python.html).
---
## Troubleshooting
See [Troubleshoot MATLAB Errors in Python](https://www.mathworks.com/help/matlab/matlab_external/troubleshoot-matlab-errors-in-python.html) for troubleshooting assistance.
---
## License
The license is available in the LICENSE.txt file within this repository.
---
## Support
Technical issues or enhancement requests can be submitted [here](https://github.com/mathworks/matlab-engine-for-python/issues).
---
Copyright © 2022 MathWorks, Inc. All rights reserved.
Linux® is the registered trademark of Linus Torvalds in the U.S. and other countries.
Mac OS is a trademark of Apple Inc., registered in the U.S. and other countries.
"Python" and the Python logos are trademarks or registered trademarks of the Python Software Foundation, used by MathWorks with permission from the Foundation.
没有合适的资源?快使用搜索试试~ 我知道了~
MATLAB Engine API for Python.zip
共21个文件
py:11个
txt:2个
yml:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 99 浏览量
2023-07-23
10:13:43
上传
评论
收藏 26KB ZIP 举报
温馨提示
MATLAB Engine API for Python.zip
资源推荐
资源详情
资源评论
收起资源包目录
MATLAB Engine API for Python.zip (21个子文件)
新建文件夹
matlab-engine-for-python-R2023a
SECURITY.md 390B
setup.py 20KB
.github
workflows
qualify_23a.yml 850B
python-publish.yml 1KB
LICENSE.txt 1KB
src
matlab
__init__.py 2KB
engine
__init__.py 7KB
enginehelper.py 1KB
matlabfuture.py 5KB
futureresult.py 4KB
matlabengine.py 10KB
basefuture.py 1KB
enginesession.py 524B
fevalfuture.py 5KB
engineerror.py 264B
_arch.txt 184B
python 0B
pyproject.toml 95B
test
tInstall.m 1KB
.gitignore 67B
README.md 5KB
共 21 条
- 1
资源评论
- lier45203692024-05-17资源很不错,内容和描述一致,值得借鉴,赶紧学起来!
AbelZ_01
- 粉丝: 895
- 资源: 5441
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功