0

Possible Duplicate:
Call python function from MATLAB

Is there a way to call functions in a Python script from MATLAB, and if so, how?

Community
  • 1
  • 1
harsha
  • 21
  • 2
  • 5
    Could you be more specific? In the general case, I think what you're asking for is impossible, but there might be a workaround depending upon the details. There's also a fair chance you're suffering from the [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) and asking the wrong question. – DSM Jan 17 '13 at 06:02
  • I have a python class containing two functions i need to call those functions in MATLAB. – harsha Jan 17 '13 at 06:20
  • For the revised question, [this previous question](http://stackoverflow.com/questions/1707780/call-python-function-from-matlab) on calling Python functions from MATLAB might be useful. – DSM Jan 17 '13 at 06:58

1 Answers1

2

You're trying to do something non-trivial. Matlab doesn't have any binding of Python-scripts, and also I don't know of a really good substitute. You can choose between two roads, maybe one can help you a little bit (though both are non-trivial, just as your task):

Convert to Python

In nowadays, Python is a valid substitute for most use cases of Matlab. There are libraries for munerical calculations, scientific routines, a great plotting library and a fantastic community that will try to help you with all your problems. And, it's free.

If you only have a couple of Matlab scripts running or you just started using Matlab I'd recommend consideringa a change of platform. To convert your existing Matlab-scripts, you could try the Open Matlab-Python-Converter.

Create a webservice using Python and access it from Matlab

The cleanest way to execute Python-Code from Matlab is to setup a webservice with Python and call this webservice from Matlab. This sounds really complicated, but it isn't. For small projects, I'd recommend XML-RPC. You can look at my other post to see an example of a small XML-RPC-server. If your methods exist, it'Ss easy to adapt to your needs, just import these methods and offer them as webservice calls.

On the Matlab side, you must stick to third-party tools for connecting to an XML-RPC server, e.g., Apache XML-RPC jars.

It might become complicated when you want to pass in other variables than primitives, e.g., arrays. I have no experience how well this works.

Community
  • 1
  • 1
Thorsten Kranz
  • 12,492
  • 2
  • 39
  • 56