views:

1550

answers:

5

I've just started experimenting something with Matlab, and since I'm used to Vim's interface, I try to stay out of Matlab's editor as much as possible. What's troubling me is that every time I start a .m file, it brings up the interface.

Is there a way to start test.m from a cmd line, and let it give output out on a cmd, as it would normally do in Matlab's environment. Something like a "Matlab shell" (like Python's, only Matlab's)?

A: 

On Linux environments, Matlab can be started in text mode

matlab -nosplash -nodesktop

but this doesn't work on Windows. which starts it in the current shell. On Windows, this opens a new text-only window. I know of no way to get it to run inside the current console on Windows.

Perhaps there's some way you can attach to it running it in http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/matlabwindows.shtml&http://www.google.com/search?rlz=1C1GGLS_enUS302US311&sourceid=chrome&ie=UTF-8&q=matlab+command+line+windows'>automation server mode.

Another option if you're really desperate could be to make a virtual machine and install linux in it. Then I imagine there are ways to configure vim to work nicely with Matlab (I'm an emacs person these days and there are solutions for emacs).

Mr Fooz
yes, it does work on windows. It will open a simple matlab command window.
Dima
+5  A: 

Are you really willing to do dev work with no m-file debugger? Seems to me that would limit you to practically trivial programs. After a very brief learning curve, I think you'd find the Matlab integrated debugger to be fantastic (and I'm a VS person).

If you insist on doing so, your best option is to compile your m-files to be runnable stand alone. That would require access to the (not cheap) matlab compiler.

Note that there is a significant difference between the compiler distributed with matlab versions up to 6.5, and those distributed with matlab 7+ (don't know the compiler version numbers). In 6.5, the compiler generated c-code, that could be than edited and compiled separately. From 7 onwards, the compiler did no compiling, converting, or any code generation for that matter: running a 'compiled' program today practically runs it on a virtual Matlab machine called the MCR - which encompasses almost all matlab functionality. It is a massive one - MCR installer (installer!) weighted 130M last time I checked.
Some debate on this can still be found on newsgroups, but that's not important now. In fact, the MCR approach seems closer to what you seek.

And btw, for me matlab -nosplash -nodesktop works perfectly on windows - it launches matlab as a console, but that would deprive you both of a text editor and a debugger...

Ofek Shilon
+2  A: 

What I would do is:

  1. Start MATLAB
  2. Do not open the .m file within matlab
  3. Open the file in your editor of choice
  4. Run the function from within MATLAB as usual

I can't imagine any reason why this wouldn't work as MATLAB should not care what was used to edit the file.

This won't give you a "shell", but the whole GUI, but I can't think of any reason why you would not want to have that, if it is available.

kigurai
You may not want the whole GUI if you have a slow computer.
Dima
+5  A: 

To answer your question, start matlab like this:

matalb -nodesktop -nosplash

This does work on both linux and windows. On linux, you type this at the command prompt, and matlab will run in that same command window in text mode. So you would get the "matlab shell" you wanted. On windows, cd into the directory where matlab is installed, and type the same command. It will open a stripped-down matlab command line window, without all the bells and whistles of the matlab desktop.

Now in my personal opinion, the matlab editor with its integrated debugger is your friend. It also has emacs key bindings, if that helps. It is also easier to execute commands and look at the results in matlab desktop then when matlab is run in text mode. The only time you really want to use the text mode is if your matlab code takes a long time to run, and you are only interested in the final result. Or if you are running multiple instances of matlab. The text mode takes much less memory, and on linux you can easily start a run from the command line and put it into background.

In fact, check the command line arguments for matlab. You can do other interesting things, like have matlab execute a single function and exit, a la perl, or redirect a script into matlab like this: matlab < script.m

Dima
A: 

I had the same problem as Kigurai. I needed to drive Matlab with Python so I found this solution:

In Python:

import os

os.chdir('W:\\monrépertoire')

os.spawnl(os.P_NOWAIT, 'monscript.bat')

In monscript.bat:

matlab.exe -r interp_3D  -nodesktop –nosplash