UP | HOME

Matlab Dev in Emacs

Table of Contents

Intro

This will show you how to set up a Matlab environment in Emacs. You'll have the matlab shell, some semblance of intelligent auto-completion, and full editor support for the language and then some.

The Setup

Requirements

Cedet
Code-analyzer package.
Auto-Complete
Code completion support. Not strictly required, but a nice bonus.

Matlab-Mode

For the full gist, go to Matlab-Emacs.

  1. Download matlab-mode by clicking the download tarball link.
    curl/wget http://matlab-emacs.cvs.sourceforge.net/viewvc/matlab-emacs/?view=tar
    tar -zxvf matlab-emacs.tar.gz
    
  2. Place it in a plugins folder of your choice, if using Prelude a simple way is:
    mkdir ~/.emacs.d/personal/plugins
    cp -r ~/Downloads/matlab-emacs ~/.emacs.d/personal/plugins/
    
  3. Add the appropriate glue to your init.el. If using Prelude this is in ~~/.emacs.d/personal/~.
    ;; Matlab support
    ;; You don't need this line if you placed it in prelude/personal
    (add-to-list 'load-path "~/emacs/plugins/matlab-emacs")
    (load-library "matlab-load")
    (matlab-cedet-setup)
    (add-hook 'matlab-mode
              (lambda ()
                (auto-complete-mode 1)
                ))
    
  4. Configure your path correctly.

    The Matlab binary is installed somewhere else than /bin likely, so you'll have to let Emacs have access to it. This is what you would do if you installed Matlab on Mac OS X.

    sudo ln -s /Applications/MATLAB_R2012a_Student.app/bin/matlab /usr/bin/matlab
    
  5. Configure Matlab's path.

    You might need to let Matlab know where to look for your files, which is easily done through the Matlab IDE (don't worry never again). This is so you can use the Matlab shell in Emacs.

    To configure your Matlab path, go to

    File > Set Path

    From there, use Add Folder… to add your main development folder that stores all your Matlab Projects. If you have lots and lots of projects, this will not scale well and you will need to find out how to dynamically load directories into Matlab. If you're in Machine Learning, just add your whole 520 folder, or add your projects one at a time to be more careful about namespace issues.

  6. Restart emacs. You should be good to go.

Commands

M-x matlab-shell

Starts the interactive matlab shell. This gives you the exact same power you had from the Matlab shell in the Matlab IDE. Things like figures, docs, that need their own window should pop out fine from the Matlab process which is running alongside Emacs.

C-M-<RET>

Evaluates the Matlab cell around point. The downside to this over a file/script though, is you get no debugging support if something goes wrong in the cell.

References

Author: Mishal Awadah

Date: 2012-11-14 17:49:49 EST

HTML generated by org-mode 7.3 in emacs 24