Is it possible to programmatically check whether MATLAB has been started with the "-nodisplay" option?
28 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
MathWorks Support Team
il 21 Gen 2010
Modificato: MathWorks Support Team
il 3 Feb 2025 alle 14:02
I have a program that needs to behave differently depending on whether MATLAB has a display or not. However, I cannot determine a way to programmatically check this.
The reason I need to do this is that I sometimes start MATLAB in batch mode from a shell script, for testing my programs.
Risposta accettata
MathWorks Support Team
il 3 Feb 2025 alle 0:00
Modificato: MathWorks Support Team
il 3 Feb 2025 alle 14:02
As of R2019a, you can use the function batchStartupOptionUsed:
In older MATLAB releases, the ability to programmatically check whether MATLAB has a display is not available. As a workaround, you can do one of the following:
1. Manually set or unset an environment variable in your shell script that launches MATLAB, so you can query it from inside MATLAB. For instance, setting the ISDISPLAY environment variable in your shell script before launching MATLAB:
setenv ISDISPLAY no
matlab -r "foo; quit"
(here shown with C Shell syntax), means that the MATLAB command
getenv('ISDISPLAY')
will return the string 'no' in any MATLAB processes that are spawned from this shell.
2. Query the "ScreenSize" property of the root object inside MATLAB:
get(0, 'ScreenSize')
When there is no display, this returns [1 1 1 1] instead of an actual screen size.
Note that this will only work in releases prior to R2014b.
0 Commenti
Più risposte (1)
Jan
il 29 Lug 2020
See also: https://www.mathworks.com/matlabcentral/answers/407059-if-matlab-desktop-elseif-matlab-nodesktop :
usejava('desktop')
or
java.lang.System.getProperty( 'java.awt.headless' )
0 Commenti
Vedere anche
Categorie
Scopri di più su Startup and Shutdown in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!