• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

jaderberg/python-matlab-bridge: A simple interface to allow Python to call MATLA ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

jaderberg/python-matlab-bridge

开源软件地址(OpenSource Url):

https://github.com/jaderberg/python-matlab-bridge

开源编程语言(OpenSource Language):

MATLAB 64.8%

开源软件介绍(OpenSource 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




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap