问题描述
一个朋友问我要创建一个小的Web界面来接受一些输入,然后将其发送给MATLAB进行数字运算并输出结果.我是一名Python/Django开发人员,因此可以处理Web界面,但是对于MATLAB却一无所知.具体来说:
A friend asked me about creating a small web interface that accepts some inputs, sends them to MATLAB for number crunching and outputs the results. I'm a Python/Django developer by trade, so I can handle the web interface, but I am clueless when it comes to MATLAB. Specifically:
- 我想真的要避免将其托管在Windows服务器上.使用Windows上创建的脚本让MATLAB在Linux上运行是否有任何问题?
- 我应该研究将命令打包还是将其编译为C并使用
ctypes
与之交互吗? - 如果要走编译的道路,那么关于将其编译并在Python中工作,我应该知道些什么吗? (自从我编译或使用C以来已经很长时间了)
- I'd really like to avoid hosting this on a Windows server. Any issues getting MATLAB running in Linux with scripts created on Windows?
- Should I be looking into shelling out commands or compiling it to C and using
ctypes
to interact with it? - If compiling is the way to go, is there anything I should know about getting it compiled and working in Python? (It's been a long time since I've compiled or worked with C)
有关如何实现此目标的任何建议,技巧或窍门?
Any suggestions, tips, or tricks on how to pull this off?
推荐答案
有一个 python-matlab桥接器,其独特之处在于Matlab作为服务器在后台运行,因此您不必每次调用Matlab函数时就拥有启动成本.
There is a python-matlab bridge which is unique in the sense that Matlab runs in the background as a server so you don't have the startup cost each time you call a Matlab function.
下载和以下代码一样简单:
it's as easy as downloading and the following code:
from pymatbridge import Matlab
mlab = Matlab(matlab='/Applications/MATLAB_R2011a.app/bin/matlab')
mlab.start()
res = mlab.run('path/to/yourfunc.m', {'arg1': 3, 'arg2': 5})
print res['result']
yourfunc.m的内容如下所示:
where the contents of yourfunc.m would be something like this:
%% MATLAB
function lol = yourfunc(args)
arg1 = args.arg1;
arg2 = args.arg2;
lol = arg1 + arg2;
end
这篇关于如何与Python中的MATLAB交互?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!