matlab - 确定 Matlab 是否有可用的显示

标签 matlab user-interface command-line

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

如果 Matlab 以 -nodisplay 选项启动,qusetdlg 会产生以下输出并“挂起”Matlab(在 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

最佳答案

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

  • -nojvm [UNIX]:在没有 JVM 的情况下启动,任何需要 Java 的东西都会失败(包括 Handle Graphics 功能)
  • -nodisplay [UNIX]: 不使用 X-Window 显示,忽略 $DISPLAY 环境变量
  • -noFigureWindows [ALL] : headless mode, no figure will be shown
  • -nodesktop [ALL] : IDE 未启动,改为命令提示符

由于我只能访问 Windows 安装的 MATLAB,如果有人可以通过使用 -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]

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]

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

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

一些引用资料:

关于matlab - 确定 Matlab 是否有可用的显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6754430/

相关文章:

c++ - 为 C++ 设置 Qt 的初学者指南

java - 带有 Clojure 的 Ubuntu 上的 GUI 系统托盘应用程序

emacs - 从命令行运行emacs并处理锁定的文件

matlab - MATLAB 中的因式分解符号表达式(和的平方)

MATLAB - 需要帮助绘制高度非线性函数

JavaFX 仅使用调试和断点更新图形

python - sys.stdin 在 ctrl-d 上不关闭

.net - 如何降级我在 cmd 上的 nuget 版本?

MatLab,如何预分配帧来制作电影?

MATLAB:如何找到满足特定条件的数字并将其标记为 "0"?