I'm learning matlab and using emacs to edit .m files.

Is there a method in Emacs to call matlab to run programs?

2 Answers 2


You can make MATLAB slurp in a .m file by feeding it to its standard input. In Emacs-speak, it is:

M-! matlab < foo.m

You might consider switching to Octave for this instead, however. Since GNU Octave is free like Emacs, you're going to find a lot more info out there about using the two together than for the non-free Matlab. Since Octave speaks much the same language as Matlab, it might be a complete replacement for your purposes.

One of the nice things you get by using Octave instead is that recent Emacsen know how to run Octave as an inferior process. This lets you have a window where you can type interactive commands and get feedback. This is very helpful while developing a more complex .m file.

Unlike MATLAB, Octave also knows how to behave like a proper Unixy scripting language. This lets you shorten the Emacs command above to:

M-! ./foo.m

Use the matlab major mode, or ocatve mode.

Either way, what you get is an interactive buffer where you can type matlab commands and get back results, as well as sending regions of text, entire function definitions, or whole files over to the running matlab process.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .