Matlab - run file without opening GUI, then quit
matlab needs to interpreter to run your commands. you can always end your file with quit
to make matlab exit again when finished with your calculations
Is there a way how to run MATLAB script from specific line without GUI?
It seems the answer is 'no': see
http://blogs.mathworks.com/desktop/2008/01/07/ive-got-something-to-cell-you/
comments 27 and 28.
Matlab run script on command line and block until finished
You can use the -wait
option above like so:
"C:\Program Files\MATLAB\R2017a\bin\matlab.exe" -wait -nodisplay -nosplash -nodesktop -r "run('C:\Users\myuser\profile.m');exit;"
How to launch MATLAB without a desktop in Windows
The -nodesktop
option was introduced when MATLAB got its Java UI. The option starts MATLAB with the previous interface. I guess they have stopped officially supporting it, but they never removed the option.
MATLAB on Windows has never been quite as comfortable running in a terminal as the Linux and macOS versions—on those OSes, MATLAB does run in the terminal with the -nodesktop
option, as they did before the Java UI was introduced.
If you want to run MATLAB non-interactively, use the -batch
option. The -r
is intended for interactive use, and therefore launches the desktop. The -batch
option:
- Starts without the desktop
- Does not display the splash screen
- Executes statement
- Disables changes to preferences
- Disables toolbox caching
- Logs text to stdout and stderr
- Does not display modal dialog boxes
- Exits automatically with exit code 0 if statement executes successfully. Otherwise, MATLAB terminates with a non-zero exit code.
(from the docs).
In your case, instead of
matlab -wait -nodesktop -nosplash -r "pause(10); quit"
you should do
matlab -batch "pause(10)"
(I don't know if -wait
is still needed on Windows, this is not clear in the documentation, and I don't have Windows to test this.)
In Matlab, is it possible to terminate a script, but save all its internal variables to workspace?
MATLAB versions 2016a and later
If you are using post 2016a versions of Matlab there is actually a pause button that appears when you run the script (as described by @pedre). This allows you to pause the script, inspect variables and then resume afterwards.
Make sure to check out the next section as this may still be convenient.
Older MATLAB versions
Actually the trick is to use dbstop if error
.
First use this, then run your script. Once you introduce an error (for example, with Ctrl+C), you then have the chance to inspect/save your workspaces manually.
You will not be able to resume the script.
Related Topics
How to Add an Icon to The Bash Prompt
How to Find a Tutorial on The Writing of Makefiles
How to Find Out What Program's on The Other End of a Local Socket
Using "Touch" to Create Directories
How to Pass Env Variables Between Make Targets
How to Check Out a Particular Version in Git from 'Git Log'
Bash Command That Prints a Message on Stderr
Only Accept Http Connections from Localhost in Go
Bash Will Not Auto-Complete (Tab) with Files
How to Find Sample Source Files for Linux Device Drivers, Third Edition
Expect, Interact and Then Again Expect
New Syscall Not Found (Linux Kernel 3.0.0) Where Should I Start Looking
How to Make Ssh Command Execution to Timeout
Opening Default Text Editor in Bash