How to Install mlabwrap on Windows
Tuesday, June 8th, 2010

It’s totally OK if you’ve never heard of mlabwrap, it is a Python extension which can build a nice connection between Python and MATLAB, lets you call MATLAB functions and M-files right in Python without further configuration.
And for those of you who comes from google, you are now using speed=10m/s to jump over this damn intro of mlabwrap.
So, Let’s Start
mlabwrap ships the following files when you’ve download it from sourceforge. The hard part is, you have to tune some of them to make sure it’s installable on your computer. The author (Alexander Schmolck) has never tested it on Windows, so it’s very hard to configure and install. But if you’re good at Python and C++, it’s another thing.

mlabwrap Files Before Installation
For the installation of mlabwrap you’ll need:
- MATLAB
- Python
- Numpy (A extension for Python)
- C Compiler (I took the Microsoft Visual C++ Express)
Make sure you install all of this before start with mlabwrap!
Some Words for MATLAB
Basically any version of MATLAB should do, but the author has point out the MATLAB 2008a can have some problem with this extension, so take MATLAB 2007, 2008b, 2009 or 2010 if you want to avoid some trouble. Besides, I prefer to install the x32 version of MATLAB and the compiler, the x64 version always gives out some not-so-good suprises.
After you have installed C compiler, you should make a short test in MATLAB base on this instruction from MathWorks to look if it’s functioning well. Otherwise you may get some strange compilation error at installing mlabwrap.
Tuning the mlabwrap
Now let’s quick tune the mlabwrap files.
1. mlabraw.cpp

The original shipped mlabraw.cpp file couldn’t pass the Visual C++ compiler on my computer, which I can’t explain. But you could change these two places to bring it back to life if you also run Visual C++ compiler.
// In line 645 change the code from if (not ok) { // To if (! ok) { // In line 768 change the code from } else if (mxIsDouble(lArray) and not mxIsSparse(lArray)) { //To } else if (mxIsDouble(lArray) && ! mxIsSparse(lArray)) {
Or you can download this file here:
2. setup.py

What this script basically does is to find out the libraries and included files for MATLAB runtime, setting the C++ compiler information for the mlabwrap installation, when all these are done, it starts the compilation and installation. Several places need to be changed in this file, pay attention to the WINDOWS identifier in the script will make it much more understandable.
At the first part, you need to manually set the MATLAB and C++ compiler paths, here are the settings for me:
MATLAB_COMMAND = 'matlab' MATLAB_VERSION = 7.3 MATLAB_DIR= 'D:/Program Files (x86)/MATLAB/R2009b' PLATFORM_DIR = None EXTRA_COMPILE_ARGS = None MATLAB_LIBRARIES = None USE_NUMERIC = None PYTHON_INCLUDE_DIR = None SUPPORT_MODULES = ["awmstools"] VC_DIR = 'D:/Program Files (x86)/Microsoft Visual Studio 9.0/VC'
After that, change the following codes, pay attention to the VC path, adjust it to meet your setting:
# In line 134 change the code from PLATFORM_DIR = PLATFORM_DIR or queried_platform_dir # To PLATFORM_DIR = 'win32/microsoft' # In line 162 change the code from MATLAB_INCLUDE_DIRS += [VC_DIR + "/include", VC_DIR + "/PlatformSDK/include"] # To MATLAB_INCLUDE_DIRS += [VC_DIR + "/include", "C:/Program Files/Microsoft SDKs/Windows/v7.0/Include"] # In line 185 change the code from runtime_library_dirs=MATLAB_LIBRARY_DIRS, # To (Yes, comment it!) #runtime_library_dirs=MATLAB_LIBRARY_DIRS,
Or you can save your time and download this file here:
And That’s All!
Now start a command window and go to your mlabwrap folder, type in the following code, mlabwrap is now installed!
python setup.py install
I’ll write another post to give you a short intro of how to bring mlabwrap to work. Feel free to leave me comments here if you still have trouble installing mlabwrap.
Related posts:
- How To Send E-Mail From MATLAB
- Exclamation Mark Your MATLAB?
- Beginner: Quick Targeting Inside Vector in MATLAB
- Better tic & toc in MATLAB
- Know the Possible Property Values
Category: MATLAB/Simulink, Software.






你们所有没有人在弄 用Dynamische Programmierung优化Hybridbetriebstrategie的?