Giter VIP home page Giter VIP logo

python-matlab-bridge's Introduction

Python-MATLAB Bridge

A simple interface to allow Python to call MATLAB functions.

Unlike other interfaces, MATLAB only has to start once. All communication is done over a TCP server (credit to D.Kroon University of Twente for the TCP server).

This has not been tested on Windows.

Usage

Initialize the Matlab class. You must pass in your matlab executable, e.g.

from pymatbridge import Matlab
mlab = Matlab(matlab='/Applications/MATLAB_R2011a.app/bin/matlab')

By default the host is localhost and the port is 4000. This can be changed, e.g.

mlab = Matlab(matlab='/Applications/MATLAB_R2011a.app/bin/matlab',
                host='192.168.0.1', port=5151)

You must then start the MATLAB server:

mlab.start()

which will return True once connected.

You can then run any local MATLAB function contained within a .m file of the same name. For example, to call the function jk in jk.m:

%% MATLAB
function lol = jk(args)
    arg1 = args.arg1;
    arg2 = args.arg2;
    lol = arg1 + arg2;
end

by calling:

res = mlab.run('path/to/jk.m', {'arg1': 3, 'arg2': 5})
print res['result']

which will print 8.

You can shut down the MATLAB server by calling

mlab.stop()

NB: you can call MATLAB code before the server starts by adding code to the ./matlab/startup.m file.

Example

An example MATLAB function and usage from Python is shown in test.py and test.m and you can also see a Notebook using the Plotly MATLAB API.

TODO

  • MATLAB error handling.
  • Multiple simultaneous connections.

Max Jaderberg 2012

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.