Skip to content

Commit 78f0153

Browse files
author
Lucas Garcia
committed
Initial commit
0 parents  commit 78f0153

28 files changed

+861
-0
lines changed

CONTRIBUTING.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Contributing
2+
3+
>_If you believe you have discovered a security vulnerability, please **do not** open an issue or make a pull request. Follow the instructions in the [SECURITY.MD](SECURITY.MD) file in this repository._
4+
5+
Thank you for your interest in contributing to a MathWorks repository! We encourage contributions large and small to this repository.
6+
7+
**Contributions do not have to be code!** If you see a way to explain things more clearly or a great example of how to use something, please contribute it (or a link to your content). We welcome issues even if you don't code the solution. We also welcome pull requests to resolve issues that we haven't gotten to yet!
8+
9+
## How to contribute
10+
11+
* **Open an issue:** Start by [creating an issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/creating-an-issue) in the repository that you're interested in. That will start a conversation with the maintainer. When you are creating a bug report, please include as many details as possible. Please remember that other people do not have your background or understanding of the issue; make sure you are clear and complete in your description.
12+
* **Work in your own public fork:** If you choose to make a contribution, you should [fork the repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo). This creates an editable copy on GitHub where you can write, test, and refine your changes. We suggest that you keep your changes small and focused on the issue you submitted.
13+
* **Sign a Contributor License Agreement (CLA):** We require that all outside contributors sign a [CLA](https://en.wikipedia.org/wiki/Contributor_License_Agreement) before we can accept your contribution. When you create a pull request (see below), we'll reach out to you if you do not already have one on file. Essentially, the CLA gives us permission to publish your contribution as part of the repository.
14+
* **Make a pull request:** "[Pull Request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests)" is a confusing term, but it means exactly what it says: You're requesting that the maintainers of the repository pull your changes in. If you don't have a CLA on file, we'll reach out to you. Your contribution will be reviewed, and we may ask you to revise your pull request based on our feedback. Once everyone is satisfied, we'll merge your pull request into the repository.
15+
16+
## Guidelines
17+
18+
We don't have best practices for writing MATLAB code, but we do have some recommendations:
19+
20+
* You should not have any warnings or errors in the [code analyzer report](http://www.mathworks.com/help/matlab/matlab_prog/matlab-code-analyzer-report.html)
21+
* [Loren Shure's blog](https://blogs.mathworks.com/loren) has [great advice on improving your MATLAB code](https://blogs.mathworks.com/loren/category/best-practice/)
22+
* Examples should be written as [live scripts](https://www.mathworks.com/help/matlab/matlab_prog/what-is-a-live-script-or-function.html) and then [exported as HTML](https://www.mathworks.com/help/matlab/matlab_prog/share-live-scripts.html).
23+
* We adhere to the [CommonMark](https://commonmark.org/) specification where it does not conflict with GitHub rendering. If you edit your Markdown in Visual Studio Code or a similar editor, it uses [markdownlint](https://github.com/DavidAnson/markdownlint) to highlight issues in your Markdown.
24+
25+
**Again, thanks for contributing, and we look forward to your issues and pull requests!**

LICENSE.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Copyright (c) 2022, The MathWorks, Inc.
2+
All rights reserved.
3+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
5+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
6+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# MATLAB Live Task for Python
2+
3+
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).
4+
5+
---
6+
7+
## Requirements
8+
### Required MathWorks Products
9+
* MATLAB R2022a or later
10+
11+
### Required 3rd Party Products
12+
* Python (supported Python versions by MATLAB release can be found [here](https://www.mathworks.com/content/dam/mathworks/mathworks-dot-com/support/sysreq/files/python-compatibility.pdf))
13+
14+
---
15+
16+
## Install
17+
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:
18+
19+
![img/pythonTaskInstall.png](img/pythonTaskInstall.png)
20+
21+
---
22+
23+
## Getting Started
24+
To insert the live task in your live script:
25+
26+
1. Go to the Live Editor tab in the Editor Toolstrip and select Task:
27+
28+
![img/pythonTask1.png](img/pythonTask1.png)
29+
30+
2. Then, choose the live task under the MY TASKS category:
31+
32+
![img/pythonTask2.png](img/pythonTask2.png)
33+
34+
Alternatively you may simply type `python` and the autocomplete feature will suggest the appropriate task:
35+
36+
![img/pythonTask3.png](img/pythonTask3.png)
37+
38+
This is what the MATLAB Live Task for Python looks like:
39+
40+
![img/pythonTask4.png](img/pythonTask4.png)
41+
42+
First, create a variable in the MATLAB workspace:
43+
```
44+
>> T = 'We at MathWorks believe in the importance of engineers and scientists. They increase human knowledge and profoundly improve our standard of living.';
45+
```
46+
47+
The Python input and output variables can be mapped with variables in the MATLAB workspace:
48+
49+
![img/pythonTask5.png](img/pythonTask5.png)
50+
51+
You can choose to write either Python statements or a Python script file:
52+
53+
![img/pythonTask6.png](img/pythonTask6.png)
54+
55+
and retrieve the required variables to be used back in MATLAB:
56+
57+
![img/pythonTask7.png](img/pythonTask7.png)
58+
59+
The equivalent MATLAB code to run either the Python statements (using [`pyrun`](pyrun)) 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:
60+
61+
![img/pythonTask8.png](img/pythonTask8.png)
62+
63+
```
64+
>> wrapped = string(wrapped)'
65+
66+
wrapped =
67+
68+
6×1 string array
69+
70+
"% We at MathWorks believe in"
71+
"% the importance of engineers"
72+
"% and scientists. They"
73+
"% increase human knowledge and"
74+
"% profoundly improve our"
75+
"% standard of living."
76+
```
77+
78+
---
79+
80+
## Examples
81+
82+
You can find examples on how to use the MATLAB Live Task for Python in the `examples` folder within this repository.
83+
84+
---
85+
86+
## Support
87+
88+
Technical issues or enhancement requests can be submitted [here](https://github.com/mathworks/MATLAB-Live-Task-for-Python/issues).
89+
90+
---
91+
92+
## License
93+
The license is available in the License file within this repository
94+
95+
Copyright © 2022 MathWorks, Inc. All rights reserved.
96+
97+
"Python" and the Python logos are trademarks or registered trademarks of the Python Software Foundation, used by MathWorks with permission from the Foundation.

SECURITY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Reporting Security Vulnerabilities
2+
3+
If you believe you have discovered a security vulnerability, please report it to
4+
[[email protected]](mailto:[email protected]). Please see
5+
[MathWorks Vulnerability Disclosure Policy for Security Researchers](https://www.mathworks.com/company/aboutus/policies_statements/vulnerability-disclosure-policy.html)
6+
for additional information.

examples/DictionaryComprehension.mlx

5.21 KB
Binary file not shown.

examples/GettingStarted.mlx

4.74 KB
Binary file not shown.
93.7 KB
Binary file not shown.

examples/kmeans.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Data conversion
2+
import numpy as np
3+
data = np.array(data)
4+
5+
# Using Scikit-learn
6+
from sklearn.cluster import KMeans as scikit_kmeans
7+
kmeans_scikit_res = scikit_kmeans(n_clusters=nclust,init='k-means++').fit(data)
8+
scikit_centroids = kmeans_scikit_res.cluster_centers_
9+
10+
# Using Scipy
11+
import scipy.cluster
12+
scipy_res = scipy.cluster.vq.kmeans2(data,k=nclust,minit='++')
13+
scipy_centroids = scipy_res[0]

img/pythonTask1.png

2.77 KB
Loading

img/pythonTask2.png

10.7 KB
Loading

img/pythonTask3.png

5.88 KB
Loading

img/pythonTask4.png

21.3 KB
Loading

img/pythonTask5.png

6.18 KB
Loading

img/pythonTask6.png

10.9 KB
Loading

img/pythonTask7.png

3.89 KB
Loading

img/pythonTask8.png

13.7 KB
Loading

img/pythonTaskInstall.png

20.7 KB
Loading

install.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
% Copyright 2022 The MathWorks, Inc.
2+
3+
addpath(genpath("src"),"-end")
4+
savepath
5+
matlab.task.configureMetadata(fullfile("src","RunPythonTask.m"))

0 commit comments

Comments
 (0)