What it is

A major mode for editing .m-files containing Matlab code. Matlab is proprietary software for numerical maths and data analysis. Also note that Emacs (21.3 onwards) comes with an alternative built in: octave mode. Octave is a free software alternative to Matlab.

How To Use It

Put into your init-file (~/.emacs, ~/.xemacs/init.el, whatever)

 (autoload 'matlab-mode "matlab" "Matlab Editing Mode" t)
  '("\\.m$" . matlab-mode))
 (setq matlab-indent-function t)
 (setq matlab-shell-command "matlab")

On Win32

MATLAB is not a CLI application on MS Windows. One needs a shell wrapper that would pipe emacs input into a Matlab and back. One can get that from . The only problem is that it does not allow multiline commands. This is crucial if one intends to use it with org-babel . There is a workaround available until better solution is found. Here it is explained how to set things up. However "" shall be replaced with '()

Here is mine C:/Programs/matlabshell/matlabshell.cmd

    @echo off
    SET PATH=C:\PROGRA~1\MATLAB\R2011a\bin;C:\PROGRA~1\MATLAB\R2011a\bin\win32
    %~dp0\matlabShell.exe 10000 20000

And here is what I have in dot emacs

    (setq matlab-shell-command "c:/Programs/matlabshell/matlabshell.cmd")
    (setq matlab-shell-command-switches '())
    (setq matlab-shell-echoes nil)

On Mac

Matlab on Mac is accessible as a CLI application on Mac (and maybe Linux) with settings similar to the following:

    % CLI matlab from the shell:
    % /Applications/ -nodesktop
    % elisp setup for matlab-mode:
    (setq matlab-shell-command "/Applications/")
    (setq matlab-shell-command-switches (list "-nodesktop"))

Wiki Pages


CategoryModes ProgrammingModes