I am new to gnu Emacs and have a question. I created an M file to run in Matlab and I got it working fine. My question is, is there a way to compile my code in the Emacs editor or test out my program? I tried the to use the "make" command and it gave me this error: Compilation exited abnormally with code. Thank you in advance for your help.
I don't use MATLAB, but this sounded like a problem I had when first starting to use emacs.
Did you originally try
M-x compile to compile your code? That will run the shell command specified by the next input. The default is
make, which is used for c programming. Here's the documentation: http://www.gnu.org/software/emacs/manual/html_node/emacs/Compilation.html#Compilation
Instead, you want to use the command line program that compiles your MATLAB code. (Is it mcc?). So the input after
M-x compile should be something like
mcc [-options] mfile1
What ever the command, it needs to be in your path variable.
Start by installing el-get; then, juts
el-get-install and select
matlab-mode. Then, have a look to
README. Here you'll find all you need. Don't forget to
At this point, you'll be able to launch the matlab shell as an inferior process, evaluate regions, lines, etc., and use
mlint to check your code.
Note that you may achieve the same using the provided
matlab-mode package when using
melpa instead of
el-get. No instruction files in this case, though.
You can run bash in a new buffer in Emacs by pressing
C-x 2 (or
C-x 3). Then go to that buffer and press
M-x shell to run
In order to run matlab in console mode you need to do the following in bash:
matlab -nodisplay -nosplash -nodesktop -r "run('yourfile.m');exit"
It's better to write the above command in a shell script that accepts the matlab file as an input.
If matlab-mode isn't installed, by default .m files are loaded in octave mode. If you aren't familiar with octave, it can run most matlab code. (Functions from some of the toolboxes aren't implemented, and some newer features are absent. For most basic things though, matlab code will run as-is in octave). This is a good option if matlab isn't available.
To get a console, use the command
run-octave, which will open a command line instance in a new window. Running scripts can be done in several ways, as others have mentioned running a shell within emacs works quite well, but emacs compilation mode provides some helpful functions.
Start compilation-mode with the
compile function. You need to change the compile-command to be
octave <<filename>>. You can also set the compile command on a per-file basis by a line similar to
## -*- compile-command: "octave test.m"; -*- as the first line in the file. I would strongly suggest creating a keybinding for compile.