Call MATLAB Script and Function From Python

by GaneshL6 in Circuits > Software

32295 Views, 10 Favorites, 0 Comments

Call MATLAB Script and Function From Python

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
MATLAB-Logo.png
  • MATLAB version R2014b or above.
  • Python version 2.7 or above.

Find MATLAB's Root Folder

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
  • 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

You will get this output for the script.py file...........

Try it out......................