Recently trying to link code in Matlab and Python became extremely sticky. From all the alternatives sockets proved to be the fastest and most reliable method of sending data back and forth. The only problem which I encounter every single time I do this (which trust me, it happens often as an entry level research assistant) is that C has very poor socket libraries. It takes more coding to create a C socket then the entire research project.For that reason this time around I invested the time to create a small, efficient and compressed library for socket communication that I can reuse in future projects.
It uses Boost (for pointers) and Zlib (for compression) but otherwise should work in any environment. If you have questions or comments don’t hesitate. (Currently it only works as a client, a possible server may also be implemented in the future)
Download the code: here
Matlab has been trying to catchup OSX for some time now. First releasing a rather bad version of Matlab for the Intel processor, and subsequently releasing a 64bit version. Both showed signs of commitment, however, today after installing Snow Leopard I was slightly annoyed that some of the functionality had become broken.
mmreader, which I depend on for reading avi movie files no longer works. Images seem to be garbled by some sort of offset and data conversion. I suspect this stems from some 32 to 64 bit conversion that Matlab is not aware of. Anyway, so now I can’t read movies files until they fix Matlab which god knows when it will be.
Update for those thinking of installing Snow Leopard: 2008a, 2009a, 2009b (32 and 64 bit) all work fine. Aside from some bugs that must exist like the one above in specific packages, the general Matlab environment is fully functional.
Currently Matlab is undergoing some major changes. While it slept for the past 5 years other programming languages have stepped up to take its place. Python, C++, Java amongst others have become as easy to use and as efficient as Matlab. The current problem, however, is that not all projects and libraries exist in all these languages. So what happens when you have a great program in Matlab and a great program in Python and you want to tie the two together? Here is my experience this weekend:
Day 1: This will be great. I’ll use the Python C API to call python from Matlab. I’ll save the Python state as a Matlab variable and I can always start up my Python session where I left off.
Day 2: Alright.. maybe not. But let’s just try calling Python from C, I just want to make it work, not have it running efficiently.
Day 3: Ok, clearly Python has a crappy API. Moving to the client/server socket communication approach. Phew.. must it be this hard?