Skip to content

SIRF and MATLAB

Kris Thielemans edited this page May 30, 2020 · 13 revisions

Using MATLAB with SIRF

SIRF can be used from MATLAB. There are however a few things you need to be aware of...

Supported MATLAB releases and compilers

If you want to use MATLAB, we strongly advise you to use a compiler supported by MATLAB, check the MathWorks web-site.

Linux

For MATLAB 2018a onwards on Linux your gcc needs to be 6.3,between 2016b and 2017b it is 4.9.2, for (somewhat) older MATLAB versions you need gcc 4.7.2.

Gadgetron needs a gcc version at least 4.8. We therefore recommend to use MATLAB 2016b or more recent. You can try to compile Gadgetron and SIRF with different compilers (but we have not tested this).

You then need to tell CMake which compiler to use. We strongly recommend to do the following before you install SIRF (for instance, for gcc 4.9):

  sudo apt-get install g++-4.9
  export CC=gcc-4.9 
  export CXX=g++-4.9

If you don’t want to use a MATLAB supported compiler, you will have problems (on Linux only?) with shared libraries that MATLAB supplies which are older than the ones you used. See also next point.

You might have problems with shared libraries which you could try to resolve by pre-loading. As an example (but you will need to adapt this to your system):

    LD_PRELOAD=/lib64/libstdc++.so.6:/lib64/libhdf5.so matlab&

Building does not find MATLAB

CMake's FindMatlab.cmake does its best to find the location of your MATLAB but can fail. It’s best to specify this from the start. You can resolve this by creating an environment variable (do this before you run CMake). For instance, on Linux/Mac when using bash

    Matlab_ROOT_DIR=/whereever/Matlab/matlab-R2016b
    export Matlab_ROOT_DIR

You can find the value for the Matlab_ROOT_DIR variable by typing matlabroot on your MATLAB prompt.

Setting the MATLAB path

You will need to add the directory where SIRF installed the MATLAB files to your MATLAB path. For instance, on the MATLAB prompt

    addpath /whereever/INSTALL/matlab

SuperBuild installation

If you prefer to install SIRF and all its dependencies using SuperBuild, then, on Linux or MacOS, MATLAB path is set by sourcing env_ccppetmr.csh or env_ccppetmr.sh - see SuperBuild installation instructions on Ubuntu and MacOS.