3

i have some python code(some functions) and i want to implement this in bigger matlab program!how can i do this?any help will be useful....

2
  • 3
    hmm seems to be a duplicate stackoverflow.com/questions/1707780/… Commented Mar 24, 2010 at 17:38
  • 2
    You might consider translating your Python functions into Matlab and avoid inter-language issues. Do some rough cost-benefit analysis and decide. Commented Mar 24, 2010 at 18:48

4 Answers 4

4

You should probably avoid this. Use one or the other - preferably Python. But if you have to use both, you could try this:

http://github.com/kw/pymex (scroll down for the readme)

Disclaimer: I wrote this. It may be somewhat difficult to get it to compile and work, particularly if you're on Windows (there is a pre-compiled win32 binary in the downloads area that might work). I don't have access to a lot of different machines with Matlab on them, so I haven't got that nailed down yet.

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

1 Comment

Thanks for releasing this code. I am trying to call cython functions from Matlab and had no idea how to start.
1

You can use the system command to execute the Python code externally. To link it in more "natively" I think you'll have to go through C. That is, embed your Python code in C code and then expose it with a DLL to Matlab.

P.S. On windows you can also expose Python code to Matlab via COM

1 Comment

@sasha: component object model: en.wikipedia.org/wiki/Component_Object_Model
1

The only thing I know of is pythoncall but it is a little out of date and I'm not sure it will work reliably with recent versions of matlab.

http://www.elisanet.fi/ptvirtan/software/pythoncall/index.html

Otherwise you would have to interact with matlab through the shell (a bit of a pain I know). If you are dealing with large amounts of data and are on an OS where you can easily create a ramdisk saving matlab files to a ramdisk and passing the filename would be one way to get data from matlab to python without too much of a performance penalty.

Comments

-2

There is a library called PyMat. It allows to call python code from matlab.

1 Comment

I didn't use it, so I don't know its limitations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.