MATLAB Community

MATLAB, community & more

Launching MATLAB without the desktop 20

Posted by Michael Katz,

I hope you don’t find it weird that I’m advertising -nodesktop mode on the Desktop blog. Don’t worry, I won’t take it personally if you decide to use this startup option. -nodesktop behaves differently depending if you are on Windows vs Linux or Mac. On Windows we provide a boring Command-Window only interface that lacks the “bells and whistles” of the regular Command Window or the full Desktop. I’m too biased to offer an opinion, but some of our users have reported they find this mode aesthetically pleasing. FYI, we recommend starting the MATLAB Desktop with the Command Window only layout instead of the -nodesktop route, Desktop -> Desktop Layout -> Command Window Only; using -nodesktop on Windows is not officially supported.

Windows nodesktop
Windows nodesktop
Linux nodesktop
Linux nodesktop

In the -nodesktop mode, you still have full access to figure windows, and you can bring up pieces of the desktop with commands like edit and commandhistory. You can launch the full desktop with the command desktop, but doing this puts control with the regular command window, and you’re left with a non-functioning -nodesktop command window window. When you bring up the Desktop in this manner, closing the Desktop window will return control to the original command window; it does not exit MATLAB.

Do not confuse this option with -nojvm option, which not only does not load the desktop, but does not load java. That means you can’t later bring up the desktop, (in the future) launch figure windows, or use any commands that use java libraries, like some of the network and file i/o functions. We don’t recommend using this option.

There’s also a -nosplash option for starting MATLAB, but this just skips the splash screen (the first window with the picture of the membrane and the version number). It still loads into the desktop.

For more information on options when launching MATLAB, here is the documentation for windows and unix.


Comments are closed.

20 CommentsOldest to Newest

David replied on : 2 of 20
The -nodesktop option is great. I'd like to use it to generate some plots on a regular basis and am wondering if you can turn off the desktop entirely. For example, if I have a test script called test.m that has the following contents:
x = 0:0.1:2*pi();
y = sin( x );
%print -dpng test.png;
saveas( gcf(), 'test.fig', 'fig' );
saveas( gcf(), 'test.png', 'png' );
And I call this script through a batch file called test.bat:
start matlab -nosplash -nodesktop -minimize -r test
Then, I can get a test.png file showing my plot as well as a copy of the data as plotted for later investigation. (As an aside, I checked and, yes, the print command and saveas produce equivalent png images.) In the process, however, the command window is brought up (minimized, thanks to the built-in Windows 'start' command) and the figure window flashes. Are there any command-line switches that prevent this from happening? It seems that on *NIX environments, one can simply set the DISPLAY environment to a null value and achieve this result, but I cannot find a way to do it in Windows... Can you offer any advice here? Thanks!
Yair Altman replied on : 3 of 20
@David - you can use the following undocumented/unsupported trick to completely hide the desktop window. Note that you will need to programmatically exit Matlab (using the exit function) because you will not be able to close the hidden window: com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame.hide Be very careful when using this, to prevent a "zombie" Matlab process that churns CPU/memory without you knowing that it still exists in the background... - Yair
Yair Altman replied on : 5 of 20
Regarding '-nodesktop' vs. '-nojvm', there is a third (undocumented/unsupported) option: '-noawt'. -noawt loads Java (thus enabling Java I/O, data structures etc.) and just prevents Java GUI. This has been a suggested compromise for remote access: - Yair
Oscar replied on : 6 of 20
I've been using Sublime Text as my text editor or choice for a minute, however I'm having a problem. I cannot figure out for the life of me how to execute anything from the editor without getting a new matlab instance to launch. It is pretty obnoxious. Is there any way to tell the matlab console to execute something in the current workspace, via the windows command line?
Mike replied on : 7 of 20
Oscar, I don't know much about that text editor, but if you are able to program it to make COM calls (it looks like a Windows program), you can set up MATLAB as an automation server I assume you are no just issuing shell commands of "MATLAB"?
Mike replied on : 9 of 20
@Bob, I take from the additional details you provided in your Stack Overflow question, that you care about running MATLAB in a batch mode, rather interactively working with it interactively. You can use the -r option when running MATLAB to kick off a script or function. If your called function saves its output to disk this should work fine. E.g.
matlab -nodesktop -r myfunction,quit
. If it's later case where you need an interactive mode, there are some rather non-trivial options, and you can contact me to discuss them offline.
Tobias replied on : 10 of 20
I have one big wish, and it’s been years I’ve been bothered by this. Please make the -nodesktop command line more libreadline-like. I know you can’t use libreadline because that’s GPL’ed, but please make out lives easier by supporting the pseudo-Emacs shortcuts that are available in the desktop CLI: ^U - Kill line to beginning ^K - Kill line to end ^W - Delete word backwards m-D - Delete words forwards etc. It’s ironic that the terminal mode of Matlab has fewer of the traditional keybindings than the Desktop CLI. A statement about this would be appreciated. I tend to use Octave just because it has readline ergonomy, but developing Mex files for it is not 100% the same.
Andrew Newell replied on : 11 of 20
What if I am writing an application that can be called from the command line but may use GUI's for some actions? Can I detect whether MATLAB is in one of these modes that are incompatible with GUI's?
Juan replied on : 13 of 20
The -nodesktop option is a lifesaver for working remotely. However, it gets completely confused when I am scrolling up my history and some history items take up more than one line. The items then get all mixed up together on the screen and it is impossible to modify particular parts of that command. Is there any way to prevent this erratic behavior? Is this a known bug that will be fixed?
Mike replied on : 14 of 20
@Juan, I don't know if that is supported, and if so, under what conditions. I recommend that you contact technical support. If it is a bug, they would know best how to work around it.
Doug Morgan replied on : 15 of 20
I'm looking for what Bob on April 14 2010 was looking for. A Windows command line to start matlab and then have matlab interact with stdin/stdout. With this you could iteractively work with text-only matlab over ssh or work with matlab in an emacs shell buffer. I remember (perhaps falsely) of doing this all the time with linux matlab and would really like to do with Windows.
Timothy W. Hilton replied on : 16 of 20
I am also interested in what Bob (14 Apr 2010) and Doug (12 Aug 2011) seek -- a way to make Matlab on a remote windows machine behave like Matlab on a remote *nix machine. You invited Bob to contact you offline for details. How does one contact you? I can't find any contact info on your blog.
Mike replied on : 17 of 20
@Doug & @Timothy, Unfortunately I've lost the original context of that conversation, so I don't recall exactly what I shared with Bob. What I probably meant was writing a shell program that uses MATLAB as a COM automation server. Or using the MATLAB Engine from a C program. It is probably easier using Windows Remote Desktop Connection or VNC to remotely access your Windows MATLAB.
Jim Van Zandt replied on : 18 of 20
I too would like to run Matlab on Windows the same way as on Linux. I use make to run Matlab programs, redirecting stdout to appropriate output files. This automates my work flow - If I update a program, I can let make figure out what (else) needs to be run to bring all output files up to date. Is there a way under Windows to run Matlab as a filter, taking input from stdin and sending output to stdout? Or even just sending output to stdout?
Brad replied on : 19 of 20
I use -nodesktop every time. However, it has an annoying bug on MacOS that no one at Mathworks seems to want to admit exists. Sometimes, esp. if I run with matlabpool, it steals the echo of the command line after I exit. This is incredibly frustrating as I have to close the terminal session every time.
Vivek replied on : 20 of 20
I am trying to postprocess data contained in hundreds of different folders (results of a batch job) using my MATLAB routine. When doing matlab -nodesktop -nosplash -r "mymatfile;quit", I get MATLAB starting up and not actually doing any operations on my data. Moreover, the MATLAB session does not terminate itself but requires me to manually enter a "quit". This would go one hundreds of times except that I exit the job. Any idea how I can get around my problem? 1) I am working in a Linux environment. 2) In the above command line, the original file is called mymatfile.m. I leave out the suffix as recommended here. 3) There is no space between the commands contained within the " quotes. Thanks, Vivek