Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab on cmd (winxp)

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)?

like image 409
Rook Avatar asked Apr 11 '09 02:04

Rook


People also ask

Can MATLAB run on Windows XP?

MATLAB 6.5 (R13) and MATLAB 6.1 (R12. 1) have been qualified under Windows XP, and will run under it. Note that there is a known display issue when using MATLAB 6.1 (R12. 1) under Windows XP, which can be corrected by running in Windows Classic Mode or by downloading and installing the hg.

Can you run MATLAB from command line?

To run a MATLAB script from the the command line, use MATLAB's -r option, as in this example which runs the Matlab script my_simulation. m from the current directory. Note that the MATLAB script that you run should have an exit command in it.

Where is MATLAB CMD?

To restore the Command Window to the default location and size, go to the Home tab, and in the Environment section, click Layout. Then, select from one of the preconfigured desktop layout options.


3 Answers

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

like image 84
Dima Avatar answered Nov 15 '22 05:11

Dima


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...

like image 25
Ofek Shilon Avatar answered Nov 15 '22 06:11

Ofek Shilon


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.

like image 25
Hannes Ovrén Avatar answered Nov 15 '22 04:11

Hannes Ovrén