# MATLAB Live Task for Python
[![View MATLAB Live Task for Python on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/111240-matlab-live-task-for-python)
The MATLAB® Live Task for Python® enables you to write and execute Python code directly inside of a MATLAB Live Script. Since R2022a, MATLAB provides a way to develop your own [custom live task](https://www.mathworks.com/help/matlab/creating_guis/live-task-development-overview.html).
---
## Requirements
### Required MathWorks Products
* MATLAB R2022a or later
### Required 3rd Party Products
* Python (supported Python versions by MATLAB release can be found [here](https://www.mathworks.com/support/requirements/python-compatibility.html))
---
## Install
Run the `install` script to add the required paths to your MATLAB environment and configure the MATLAB Live Task for Python. Click 'Ok' when promtped with the following UI to configure the Live Editor task metadata:
![img/pythonTaskInstall.png](img/pythonTaskInstall.png)
---
## Getting Started
To insert the live task in your live script:
1. Go to the Live Editor tab in the Editor Toolstrip and select Task:
![img/pythonTask1.png](img/pythonTask1.png)
2. Then, choose the live task under the MY TASKS category:
![img/pythonTask2.png](img/pythonTask2.png)
Alternatively you may simply type `python` and the autocomplete feature will suggest the appropriate task:
![img/pythonTask3.png](img/pythonTask3.png)
This is what the MATLAB Live Task for Python looks like:
![img/pythonTask4.png](img/pythonTask4.png)
First, create a variable in the MATLAB workspace:
```
>> T = 'We at MathWorks believe in the importance of engineers and scientists. They increase human knowledge and profoundly improve our standard of living.';
```
The Python input and output variables can be mapped with variables in the MATLAB workspace:
![img/pythonTask5.png](img/pythonTask5.png)
You can choose to write either Python statements or a Python script file:
![img/pythonTask6.png](img/pythonTask6.png)
and retrieve the required variables to be used back in MATLAB:
![img/pythonTask7.png](img/pythonTask7.png)
The equivalent MATLAB code to run either the Python statements (using [`pyrun`](https://www.mathworks.com/help/matlab/ref/pyrun.html)) or a Python script (using [`pyrunfile`](https://www.mathworks.com/help/matlab/ref/pyrunfile.html)) is generated and run automatically by default like any live task:
![img/pythonTask8.png](img/pythonTask8.png)
```
>> wrapped = string(wrapped)'
wrapped =
6×1 string array
"% We at MathWorks believe in"
"% the importance of engineers"
"% and scientists. They"
"% increase human knowledge and"
"% profoundly improve our"
"% standard of living."
```
---
## Examples
You can find examples on how to use the MATLAB Live Task for Python in the `examples` folder within this repository.
---
## Support
Technical issues or enhancement requests can be submitted [here](https://github.com/mathworks/MATLAB-Live-Task-for-Python/issues).
---
## License
The license is available in the License file within this repository
Copyright © 2022 MathWorks, Inc. All rights reserved.
"Python" is a registered trademark of the Python Software Foundation.
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
MATLAB-Live-Task-for-Python-master.zip (28个子文件)
MATLAB-Live-Task-for-Python-master
SECURITY.md 389B
LICENSE.txt 1KB
src
resources
liveTasks.json 334B
PythonLiveTaskIcon.png 17KB
RunPythonTask.m 41KB
images
folder.png 422B
plus.png 304B
down.png 319B
arrow-right.png 348B
up.png 306B
minus.png 292B
CONTRIBUTING.md 3KB
examples
ValidateConclusions_kmeans.mlx 94KB
DictionaryComprehension.mlx 5KB
GettingStarted.mlx 5KB
kmeans.py 396B
img
pythonTask2.png 10KB
pythonTask5.png 6KB
pythonTask4.png 21KB
pythonTask8.png 14KB
pythonTask3.png 6KB
pythonTask6.png 11KB
pythonTask1.png 3KB
pythonTaskInstall.png 20KB
pythonTask7.png 4KB
uninstall.m 70B
install.m 142B
README.md 3KB
共 28 条
- 1
资源评论
ai20220125
- 粉丝: 1
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功