确定Matlab是否有可用的显示 [英] Determine if Matlab has a display available

查看:513
本文介绍了确定Matlab是否有可用的显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Matlab应用程序中使用 questdlg 来提示用户反馈。如果没有显示可用(例如,通过非转发的ssh会话或如果Matlab以 -nodisplay 开始), questdlg 失败(见下文)。有没有什么方法来确定显示是否可以从Matlab代码中,以便我可以回到基于文本的替代?

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?

如果Matlab是以 -nodisplay 选项, qusetdlg 产生以下输出和挂起Matlab(在 uiwait )。虽然用户可以使用 Ctl-C 来转义,但没有迹象表明这个选项,一个天真的用户可能会得出结论,Matlab是真的挂起:

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


推荐答案

首先,下面是相关启动选项的列表,以及支持它们的操作系统(否则它们被忽略并且没有效果):

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]:不使用JVM启动,任何需要Java失败图形功能)

  • -nodisplay [UNIX]:不使用X-Window显示,忽略 $ DISPLAY 环境变量

  • -noFigureWindows [ALL]:无头模式, >
  • -nodesktop [ALL]:IDE未启动,指令提示

  • -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

由于我只能访问Windows安装的MATLAB,我会感激如果有人可以复制以下实验在UNIX上,启动MATLAB与 -nodisplay 选项或没有 DISPLAY 环境变量集的运行与 -nodisplay -nojvm 选项。

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.

» [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]


b $ b

matlab -noFigureWindows



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



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

一些参考资料:

  • Changes to -nojvm Startup Option
  • Changes to -nodisplay and -noFigureWindows Startup Options
  • usejava, javachk
  • matlabwindows, matlabunix
  • which -all warnfiguredialog.m

这篇关于确定Matlab是否有可用的显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆