MATLink — Communicate with MATLAB from Mathematica

4 min read Original article ↗
  • Mathematica version 8.0.4 or higher
  • MATLAB R2011a (version 7.12) or higher
  • A version of Windows/Linux/OS X that can run both Mathematica and MATLAB

MATLink has been extensively tested with Mathematica versions 8.0.4, 9.0.1 and 10.0.0, MATLAB 2012b, 2013a and 2013b on OS X 10.8 and 10.9, and moderately tested on Windows 8 and Ubuntu 13.04. If you encounter any issues with a relatively modern operating system or a supported Mathematica/MATLAB version, please open a new issue at GitHub.

Warning: On OS X and Linux, MATLAB R2014a contains a bug that breaks MATLink. Please use an different version of MATLAB with MATLink on these systems. Older or newer versions (R2013b or R2014b) are not affected by the problem. The Windows version of MATLAB R2014a is not affected by this problem and works well with MATLink.

Next: Choose your preferred download option and install MATLink

Windows

Although MATLink ships with pre-compiled binaries, depending on your specific setup, it might be necessary to manually change a few settings before you can begin to use MATLink. If it does not work out of the box, please try following the instructions below:

  1. Add MATLAB's bin\win64 directory (bin\win32 for 32-bit versions) to the operating system's PATH environment variable.
  2. Register the default MATLAB version by running regmatlabserver in MATLAB. On most Windows systems, you will need administrator rights to do this.
  3. If you're using a 32 bit MATLAB (such as a student version) with a 64 bit Mathematica, then evaluate the following before using OpenMATLAB[] for the first time (needs to be done only once)

    Needs["MATLink`"]
    SetOptions[MATLink, "Force32BitEngine" -> True]
    

    If you reset your Mathematica settings or remove MATLink's init.m in $UserBaseDirectory/ApplicationData/MATLink, then the above option will need to be set again.

You should now be all set to use MATLink! If for some reason it fails, please open a new issue on GitHub.

Linux

Although MATLink ships with pre-compiled binaries, depending on your specific setup, it might be necessary to manually change a few settings before you can begin to use MATLink. If it does not work out of the box, please try following the instructions below:

  1. To run the MATLink engine, you must have the C shell csh installed at /bin/csh (more info).
  2. A C++ compiler is needed to compile the MATLink binary. Old versions of gcc cannot be used to compile MATLink. The compiler requirements depend on your version of MATLAB and are documented by the MathWorks.
  3. Development libraries for libuuid must be installed.
  4. Both Mathematica and MATLAB must be on the system PATH (i.e., which matlab and which math return the correct locations).

You should now be all set to use MATLink! If for some reason it fails, please open a new issue on GitHub.

OS X

Although MATLink ships with pre-compiled binaries, depending on your specific setup, it might be necessary to manually change a few settings before you can begin to use MATLink. If it does not work out of the box, please try following the instructions below:

  1. Navigate to the MATLink/Engine/bin/MacOSX64 directory, edit the file mengine.sh and set the path to the MATLAB app bundle. This is not necessary if MATLAB is installed in the default folder in /Applications (e.g. /Applications/MATLAB_R2013a.app)

You should now be all set to use MATLink! If for some reason it fails, please open a new issue on GitHub.