2

I need to call these Python functions from Matlab. something like this:

  matplotlib.pyplot 
  matplotlib 
  numpy 

But I don't know how to begin with. e.g., I installed Python on my computer but didn't help etc ... I need to learn it from scratch I also look at below link but didn't help :( Call Python function from MATLAB

seralouk
  • 30,938
  • 9
  • 118
  • 133
Roxana
  • 71
  • 4
  • 2
    For starting out, it will be much easier to learn Python without having the extra layer of trying to use it from within MATLAB. I would learn some Python first, before you start mixing the two. You might even find you don't need MATLAB any more... – Matt Hall Oct 04 '19 at 13:51
  • 1
    SO is not a tutorial site. It is also not a site to help you search for documentation. When you have done your research and made a specific attempt, we might be able to help, as long as you follow the rules in https://stackoverflow.com/help/how-to-ask – Mad Physicist Oct 04 '19 at 13:54

2 Answers2

0

You need to open Matlab from the terminal:

Go to the bin:

cd /Applications/MATLAB_R2019a.app/bin/

Open it:

./matlab

Next, to use Python type:

!python

This answer assumes that you have already installed Python on your system.

enter image description here

seralouk
  • 30,938
  • 9
  • 118
  • 133
0

Recently, I designed a MATLAB controller for some hardware but the scripts to control the hardware were written in Python.

As an example, I have a python script in the same working directory called test.py

def hello():
    return "Hello World!"

In MATLAB, I can run this script using the command: py.test.hello

Image of my MATLAB command window output

It returns a friendly message :)

wgb22
  • 247
  • 1
  • 13