From Slicer Wiki
Jump to: navigation, search
Home < Documentation < 4.3 < Extensions < MatlabBridge

For the latest Slicer documentation, visit the read-the-docs.

Introduction and Acknowledgements

Author: Andras Lasso (PerkLab, Queen's University), Jean-Christophe Fillion-Robin (Kitware), Kevin Wang (Radiation Medicine Program, Princess Margaret Hospital, University Health Network Toronto), Gabor Fichtinger (PerkLab, Queen's University)
Contact: Andras Lasso, <email></email>
Project website:
License: Slicer license


Extension Description


MatlabBridge is an extension of 3D Slicer to allow running Matlab functions directly in 3D Slicer.


  • The extension allows running of Matlab functions directly from 3D Slicer: it takes the input from the data loaded into Slicer and visualizes the results in Slicer right after the execution is completed
  • If you change any input on the GUI (and the “AutoRun” option is enabled) the bridge automatically re-runs the Matlab script with the updated parameters and shows the new results
  • If you change your Matlab function then you can re-run the function and see the updated results with a single click
  • The graphical user interface is generated automatically from a standard command-line interface definition XML file (no GUI programming needed)
  • You can get started quickly by generating a skeleton Matlab function and interface definition XML file using the Matlab Module Generator module
  • No building of 3D Slicer or MEX files, etc. are needed – the only requirements are to download and install 3D Slicer with the MatlabBridge extension and have Matlab on your computer

The Matlab module behaves exactly as any other command-line-interface module, the Matlab engine is started automatically in the background (and it is kept running in the background so that you don’t have to wait for Matlab startup each time you run your function)

Demo videos:

Tutorial: How to create, run, customize Matlab modules


Use Cases


Information for Developers


  • Problem: When I try to run my Matlab module, the Matlab process does not start (Matlab window does not appear on the taskbar)
    • Solution [on Windows Vista/7/8]: Please go to the Matlab module generator module and in the “Matlab executable” editbox set the path to your “.../bin/matlab.exe” (not to "activate_matlab.exe" or other exe files in the Matlab program directory or any file in the bin/win64 directory).
    • Solution [on Mac OS X]: Please go to the Matlab module generator module and in the “Matlab executable” editbox set the path to your “/Applications/” (instead of you may have MATLAB_<Release>.app, where <Release> is the MATLAB Release's version, i.e., R2009a, R2012b, etc.).
  • Problem: When I try to run my Matlab module, the Matlab process starts (Matlab window appears on the taskbar and it displays the message "Starting OpenIGTLink command server at port 4100 Waiting for client connections..."), but the Matlab module execution fails (in the Slicer error log the "igtl::ClientSocket (...): Failed to connect to server" message is displayed)
    • Solution [on Windows Vista/7/8]: Firewall settings prevent Matlab-Slicer communication. Please add a firewall exception by the following steps:
      1. Start cmd.exe as administrator (open the Windows Start menu, type "cmd", hit Ctrl + Shift + Enter)
      2. Click Yes, if a dialog box appears asking "Do you want to allow the following program to make changes to this computer?"
      3. Enter the following command: netsh firewall add portopening tcp 4100 MatlabBridge
    • Solution [on Mac OS X]: Firewall settings prevent Matlab-Slicer communication. Please disable firewal or add a firewall exception.
  • Problem: module execution is not completed
    • Solution: make sure you've selected .../MATLAB/.../bin/matlab.exe as Matlab executable (and not .../MATLAB/.../bin/win64/MATLAB.exe)