Call MATLAB Script and Function From Python
by GaneshL6 in Circuits > Software
32349 Views, 10 Favorites, 0 Comments
Call MATLAB Script and Function From Python
![maxresdefault.jpg](/proxy/?url=https://content.instructables.com/FQ7/N2I6/J9OWL8XG/FQ7N2I6J9OWL8XG.jpg&filename=maxresdefault.jpg)
Hi friends . In this instructable I will show you how to run MATLAB scripts and call MATLAB functions from python code.
Softwares Needed
![python.png](/proxy/?url=https://content.instructables.com/FXB/VH8F/J9OWNJWE/FXBVH8FJ9OWNJWE.png&filename=python.png)
![MATLAB-Logo.png](/proxy/?url=https://content.instructables.com/F8F/V8JN/J9OWNJXD/F8FV8JNJ9OWNJXD.png&filename=MATLAB-Logo.png)
- MATLAB version R2014b or above.
- Python version 2.7 or above.
Find MATLAB's Root Folder
![Capture1.PNG](/proxy/?url=https://content.instructables.com/FNX/TMTY/J9OWNHCY/FNXTMTYJ9OWNHCY.png&filename=Capture1.PNG)
- Open MATLAB.
- Type "matlabroot" in command window of MATLAB.
- Answer shows the root folder of the MATLAB that you have installed.
Install Python API for MATLAB
![Capture2.PNG](/proxy/?url=https://content.instructables.com/FEB/C1C9/J9OWNI5E/FEBC1C9J9OWNI5E.png&filename=Capture2.PNG)
- Open Command Prompt and change the directory to "C:\Program Files\MATLAB\R2017a> cd extern\engines\python"
- Run "setup.py" in that directory by using this command "python setup.py install"
Code
- script.py used to run a MATLAB script named basicsignals.m
function.py used to call the MATLAB function named triarea
Output
![basicsignals.png](/proxy/?url=https://content.instructables.com/FPT/Y4L5/J9OWNJUB/FPTY4L5J9OWNJUB.png&filename=basicsignals.png)
You will get this output for the script.py file...........
Try it out......................