Rook
Rook

Reputation: 62588

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

Upvotes: 6

Views: 7392

Answers (6)

mlt
mlt

Reputation: 1669

There are cases when indeed not much debugging is needed and state of the Matlab shall be preserved between invocations. One (the only?) example would be Emacs org-mode . it can be used to write text interleaved with code according to literate programming etc. While it is possible to use comments in Matlab and publish code be it HTML or LaTeX, it does however require to leave the comfort of Emacs.

There is a standalone program available that uses Matlab engine to evaluate commands received on stdin, and dump the result. This particular version, however, lacks support for multiline commands like if/else/end or for/end. This is a limitation of engEvalString that expects everything at once. There is an ugly workaround available that makes it usable enough for org-mode.

#+begin_src matlab :session *MATLAB* :exports none :cache no :results value
if 3>1
 'wow!!!'
end
#+end_src

#+RESULTS:
: wow!!!

Upvotes: 0

Veronique
Veronique

Reputation:

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

Upvotes: 0

Ofek Shilon
Ofek Shilon

Reputation: 16217

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

Upvotes: 5

Mr Fooz
Mr Fooz

Reputation: 111996

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

Upvotes: 0

Dima
Dima

Reputation: 39429

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

Upvotes: 10

Hannes Ovr&#233;n
Hannes Ovr&#233;n

Reputation: 21851

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.

Upvotes: 2

Related Questions