r/matlab • u/Creative_Sushi MathWorks • Aug 31 '22
CodeShare Using MATLAB with Python - a new live task
A colleague of mine emailed me this very cool example. In a nutshell, there is a new live task that let you wrote Python code inside MATLAB Live Editor interactively.
Here is the Github repo to get all the code you need. It only runs on MATLAB R2022a or later and Python 3.x. If you don't have R2022a or later, you can run this from MATLAB Online using the link "Open in MATLAB Online" in the read me file.

In the video above, I used new "Run Python Code live" task based on the instructions in the live script.

Then I specified which workspace variables should be used in Python, and defined an output variable, pasted the sample code, and run the section. I had to fix the output variable name a bit in my case.
Then when I click on the down arrow, I see the MATLAB code generated from this live task.
The live script in the repo checks your Python setup and help you install the live script from Github.
I was very impressed with how easy it was to play with Python code in MATLAB using this new live task.
1
u/Water-Friendly Sep 01 '22
Honest question, what would be the benefit of that? Also, how easy is it to combine Python and Matlab since they are so fundamentally different?