Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

share|improve this question

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
share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.