确定Matlab是否有可用的显示

Bar*_*ark 20 matlab user-interface command-line

我想questdlg在Matlab应用程序中使用以提示用户反馈.如果没有可用的显示(例如,通过非转发的ssh会话或者如果启动了Matlab -nodisplay),则questdlg失败(见下文).有没有办法确定是否可以从Matlab代码中获得显示,以便我可以回退到基于文本的替代方案?

如果使用该-nodisplay选项启动Matlab ,则qusetdlg生成以下输出并"挂起"Matlab(in uiwait).虽然用户可以使用它Ctl-C来逃避,但没有任何迹象表明这个选项,一个天真的用户可能会得出Matlab真正挂起的结论:

>> 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
Run Code Online (Sandbox Code Playgroud)

Amr*_*mro 27

首先,这里是相关启动选项的列表,以及支持它们的操作系统(否则它们将被忽略并且不起作用):

  • -nojvm [UNIX]:从没有JVM开始,任何需要Java的东西都失败了(包括Handle Graphics功能)
  • -nodisplay[UNIX]:不使用X-Window显示,忽略$DISPLAY环境变量
  • -noFigureWindows [ALL]:无头模式,不会显示数字
  • -nodesktop [ALL]:IDE未启动,而是命令提示符

因为我只能访问Windows安装的MATLAB,所以如果有人可以在UNIX上复制以下实验,通过使用该-nodisplay选项启动MATLAB ,或者在没有设置DISPLAY环境变量的情况下运行,并结合使用-nodisplay-nojvm选项,我将会感激不尽.

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]
Run Code Online (Sandbox Code Playgroud)

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]
Run Code Online (Sandbox Code Playgroud)

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]
Run Code Online (Sandbox Code Playgroud)

总之,这是我将用于跨平台获得一致结果的测试:

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

一些参考: