views:

322

answers:

3

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:

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

A: 

Perhaps you'll find useful information here

PyMat - An interface between Python and MATLAB

Sorantis
-1 - sorry but this is really out of date and will prob have trouble getting it to build (the docs still refer to Numeric)... mlabwrap is the way to go (actively maintained and works with recent matlab)
thrope
+3  A: 

Take a look at mlabwrap which allows you to call Matlab via a python API:

http://mlabwrap.sourceforge.net/

Jon
I second mlabwrap. Though, I would prefer a pure Python solution like numpy, I'm currently using mlabwrap to read some data from file, preprocess it in Python send to Matlab and then get the results.You may have overhead problems with starting the Matlab environment everytime a request comes.
Amaç Herdağdelen
I also agree that mlabwrap is insanely easy to use. However, as Amac said, the overhead is quite significant. To put some numbers to this, a computation I'm using (function optimization.lsqlin) takes 0.01 seconds to finish when calling it from matlab, but when calling it from python with the same parameters using mlabwrap it takes 0.30 seconds to finish.
Spike
+1  A: 

Regarding OS compatibility, if you use the matlab version for Linux, the scripts written in windows should work without any changes. If possible, you may also consider the possibility of doing everything with python. Scipy/numpy with Matplotlib provide a complete Matlab replacement.

Raja