views:

602

answers:

4

A researcher has created a small simulation in MATLAB, and we want to make it accessible to others. My plan is to take the simulation, clean up a few things, and turn it into a set of functions. Then, I plan to compile it into a C library and use SWIG to create a Python wrapper. At that point, I should be able to call the simulation from a small Django app. At least, I hope so.

Do I have the right plan? Has anyone else done something similar? Can you let me know if there are some serious pitfalls I'm not aware of at the moment?

+1  A: 

I won't help much but I remember that I was able to wrap MATLAB simulation into DLL and then call it from Delphi app. It work really well.

Anyway: good luck!!!

Michal Sznajder
A: 

Perhaps try ctypes instead of SWIG. If it has been included as a part of Python 2.5, then it must be good :-)

Bartosz Radaczyński
A: 

I'd also try ctypes first.

  1. Use the Matlab compiler to compile the code into C.
  2. Compile the C code into a DLL.
  3. Use ctypes to load and call code from this DLL

The hardest step is probably 1, but if you already know Matlab and have used the Matlab compiler, you should not have serious problems with it.

Eli Bendersky
+1  A: 

One thing to remember is that the Matlab compiler does not actually compile the Matlab code into native machine instructions. It simply wraps it into a standalone executable or a library with its own runtime engine that runs it. You would be able to run your code without Matlab installed, and you would be able to interface it with other languages, but it will still be interpreted Matlab code, so there would be no speedup.

Dima