Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if Matlab has a display available

Tags:

I would like to use questdlg within a Matlab application to prompt user feedback. If no display is available (e.g. over a non-forwarded ssh session or if Matlab is started with -nodisplay), questdlg fails (see below). Is there any way to determine if a display is available from within Matlab code so that I can fall back to a text-based alternative?

If Matlab is started with the -nodisplay option, qusetdlg produces the following output and "hangs" Matlab (in uiwait). Although the user can use Ctl-C to escape, there's no indication of this option and a naive user might conclude that Matlab was truly hung:

>> questdlg('test','test')
Warning: This functionality is no longer supported under the -nodisplay and
-noFigureWindows startup options. For more information, see "Changes to
-nodisplay and -noFigureWindows Startup Options" in the MATLAB Release Notes.
To view the release note in your system browser, run
web('http://www.mathworks.com/access/helpdesk/help/techdoc/rn/br5ktrh-1.html#br5ktrh-3',
'-browser') 
> In uitools/private/warnfiguredialog at 19
  In dialog at 37
  In questdlg at 117
Warning: This functionality is no longer supported under the -nodisplay and
-noFigureWindows startup options. For more information, see "Changes to
-nodisplay and -noFigureWindows Startup Options" in the MATLAB Release Notes.
To view the release note in your system browser, run
web('http://www.mathworks.com/access/helpdesk/help/techdoc/rn/br5ktrh-1.html#br5ktrh-3',
'-browser') 
> In uitools/private/warnfiguredialog at 19
  In uiwait at 41
  In questdlg at 378
like image 500
Barry Wark Avatar asked Jul 19 '11 21:07

Barry Wark


People also ask

How do I know if my MATLAB has a Signal Processing Toolbox?

In MATLAB, go to the Home tab. 2. Select Add-Ons > Manage Add-Ons. MATLAB displays a list of MathWorks products, toolboxes, and add-ons installed on your machine.

How do I check my MATLAB license status?

Direct link to this answer If MATLAB is already installed: Within the MATLAB command type "license" and hit enter to view your License number in the output.

How do you check if a string contains a character MATLAB?

TF = contains( str , pat ) returns 1 ( true ) if str contains the specified pattern, and returns 0 ( false ) otherwise.


2 Answers

First of all, here is a list of relevant startup options, along with the operating system on which they are supported (otherwise they are ignored and have no effect):

  • -nojvm [UNIX] : start without JVM, anything that requires Java fails (including Handle Graphics functionality)
  • -nodisplay [UNIX]: does not use X-Window display, ignores $DISPLAY environment variable
  • -noFigureWindows [ALL] : headless mode, no figure will be shown
  • -nodesktop [ALL] : IDE not started, command prompt instead

Since I only have access to a Windows install of MATLAB, I would be thankful If someone can replicate the following experiments on UNIX, by starting MATLAB with the -nodisplay option, or runing without the DISPLAY environment variable set, in combination with the -nodisplay and -nojvm options.

matlab -nodesktop

» [usejava('jvm'),usejava('awt'),usejava('mwt'),usejava('Desktop')]
ans =
     1     1     1     0
» get(0,'ScreenSize')
ans =
           1           1        1600        1024
» feature('ShowFigureWindows')
ans =
     1
» questdlg('?','?');
[works fine]
» plot(1:10)
[works fine]

matlab -noFigureWindows

» [usejava('jvm'),usejava('awt'),usejava('mwt'),usejava('Desktop')]
ans =
     1     1     1     1
» get(0,'ScreenSize')
ans =
           1           1        1600        1024
» feature('ShowFigureWindows')
ans =
     0
» questdlg('?','?');
Warning: This functionality is no longer supported ....
» plot(1:10)
[no plot]

matlab -nodesktop -noFigureWindows

» [usejava('jvm'),usejava('awt'),usejava('mwt'),usejava('Desktop')]
ans =
     1     1     1     0
» get(0,'ScreenSize')
ans =
           1           1        1600        1024
» feature('ShowFigureWindows')
ans =
     0
» questdlg('?','?');
Warning: This functionality is no longer supported ....
» plot(1:10)
[no plot]

In conclusion, this is the test I would use to get consistent results across platforms:

if usejava('jvm') && ~feature('ShowFigureWindows')
    %# use text-based alternative (input)
else
    %# use GUI dialogs (questdlg)
end

Some references:

  • Changes to -nojvm Startup Option
  • Changes to -nodisplay and -noFigureWindows Startup Options
  • usejava, javachk
  • matlabwindows, matlabunix
  • which -all warnfiguredialog.m
like image 92
Amro Avatar answered Sep 19 '22 22:09

Amro


This MATLAB newsgroup thread suggests that checking the third and fourth values of the root object 'ScreenSize' property will tell you if a display is available. I can't test it at the moment, but you could try adding this to your code:

screenSize = get(0,'ScreenSize');
if isequal(screenSize(3:4),[1 1])
  %# Use text-based alternative
else
  %# Call questdlg
end
like image 33
gnovice Avatar answered Sep 21 '22 22:09

gnovice