如何隐藏“MATLAB 命令行窗口”当我从命令行运行 m 文件时?
我使用如下命令行字符串运行 MATLAB:
C:\\matlab.exe -nodisplay -nosplash -nodesktop -r "run('C:\ ;\mfile.m');"
m 文件包含一个 plot()
函数,用于在 xy 平面上绘制一条简单曲线。
m 文件成功运行并使用我上面指定的命令行字符串绘制绘图。但是,每次运行此命令时,都会出现一个名为“MATLAB Command Window”的窗口以及绘图。
如何使“MATLAB 命令行窗口”不出现,以便只有绘图可见。
“MATLAB 命令行窗口”如下所示:
I am running MATLAB with a command line string like this:
C:\<a long path here>\matlab.exe -nodisplay -nosplash -nodesktop -r "run('C:\<a long path here>\mfile.m');"
The m-file contains a plot()
function to plot a simple curve on the x-y plane.
The m-file successfully runs and draws the plotting with the command line string I specified above. However, every time I run this command, a window named "MATLAB Command Window" appears along with the plotting.
How do I make this "MATLAB Command Window" NOT appear, so that only the plotting will be visible.
The "MATLAB Command Window" looks like below:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您是从 Windows 上的另一个程序运行 Matlab,则可以使用 Matlab COM 自动化服务器。 ActiveX 控件有一个 Visible 属性,可以让您使命令窗口不可见,但看起来它使绘图可见。
下面是如何使用另一个 Matlab 作为控制器来完成此操作的示例。
或者在 VBScript 中。
无论如何,这种交互模式可能更符合您的需求,具体取决于您的工作流程的结构,因为它可以让您启动一次 Matlab 进程并对其发出多次绘图请求,从而节省启动成本并让您在一次。
如果您仍然想从命令行调用它,只需使用上述 VBScript 代码通过 .vbs 包装脚本运行它,但调用
run('...\mfile.m')
而不是冲浪(峰值)
。您的 mfile.m 将需要一些 GUI 逻辑,使其阻塞,直到用户关闭绘图,替换pause
调用,以便在用户完成查看之前它不会消失。If you are a running Matlab from another program on Windows, you can run it using the Matlab COM Automation Server. The ActiveX control has a Visible property which will let you make the command window invisible, but looks like it leaves the plots visible.
Here's an example of how to do it using another Matlab as the controller.
Or in VBScript.
This interaction mode might be more what you want anyway, depending on how your workflow is structured, because it'll let you fire up the Matlab process once and make many plot requests on it, saving startup costs and letting you have multiple plots visible at once.
If you still want to call it from a command line, just run it through a .vbs wrapper script with the above VBScript code, but call
run('...\mfile.m')
instead ofsurf(peaks)
. Your mfile.m will need some GUI logic that makes it block until the user dismisses the plot, replacing thepause
call, so it doesn't disappear before they're done viewing it.好消息!
通过一些 Java 操作,这是可能的! 正常启动 MATLAB(通过桌面等)。现在运行 setDesktopVisibility (假)瞧!例如
,据我所知,您无法在 Windows 上使用
matlab.exe
的选项来完成此操作。如果您确实需要隐藏它,我建议使用 MATLAB 引擎 显示您的身材。另外,如果是为了简单的事情,比如绘图等,你可以使用 GNU Octave ,它可以与M 文件,并且没有像 MATLAB 那样的“命令窗口”(它在 Windows 命令提示符中运行,隐藏它并不难)。Great news!
With a bit of Java manipulation, it is possible! Start MATLAB normally (with the desktop etc.) Now run setDesktopVisibility(false) and voila! E.g.
AFAIK you can't do it on Windows using the options with
matlab.exe
. If you really need to hide it, I'd recommend using the MATLAB Engine to display your figure. Additionally, if it's for simple things like plotting, etc. you could use GNU Octave which works with M files and does not have a "Command Window" like MATLAB does (it runs in the Windows Command Prompt and hiding it is not that hard).运行:
,这将在用户会话中显示最小化的窗口。根据Amro的建议,我们可以将最小化的窗口发送到本地的winlogin会话,这样我们就看不到最小化的Window:
了,它会默默地将图形保存到C:\Windows\System32(如果启用了ISD服务,可能会弹出一个交互式服务检测对话框窗口,并且 /s 或 /x 选项在 Windows Server 2003 或 2008 中不起作用。)
Run:
,which will show a minimized Window in the user session. By suggestion from Amro, we can send the minimized window to winlogin session locally so that we even cannot see the minimized Window:
,which will save the figure to C:\Windows\System32 silently (if ISD service is enabled it may pop up an interactive services detection dialog window, and /s or /x option do not work in Windows server 2003 or 2008.)
您可以从命令行使用它:
You can probably use it from the command-line as: