Call MATLAB Script and Function From Python

23,209

9

1

Introduction: Call MATLAB Script and Function From Python

About: Engineering Student................

Hi friends . In this instructable I will show you how to run MATLAB scripts and call MATLAB functions from python code.

Step 1: Softwares Needed

  • MATLAB version R2014b or above.
  • Python version 2.7 or above.

Step 2: Find MATLAB's Root Folder

  • Open MATLAB.
  • Type "matlabroot" in command window of MATLAB.
  • Answer shows the root folder of the MATLAB that you have installed.

Step 3: Install Python API for MATLAB

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

Step 4: Code

  • script.py used to run a MATLAB script named basicsignals.m
  • function.py used to call the MATLAB function named triarea

Step 5: Output

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

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

Raspberry Pi Contest 2017

Participated in the
Raspberry Pi Contest 2017

Be the First to Share

    Recommendations

    • Battery Powered Contest

      Battery Powered Contest
    • Plywood Challenge

      Plywood Challenge
    • Plastic Contest

      Plastic Contest

    Discussions

    0
    d.rittau
    d.rittau

    7 months ago

    It works perfect!
    I'm using jupyter notebook and had just to upload both file in the same folder.
    Thank you for the good explenation!