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?

3
  • 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 and asking the wrong question. Commented Jan 17, 2013 at 6:02
  • I have a python class containing two functions i need to call those functions in MATLAB. Commented Jan 17, 2013 at 6:20
  • For the revised question, this previous question on calling Python functions from MATLAB might be useful. Commented Jan 17, 2013 at 6:58

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.