如何隐藏“MATLAB 命令行窗口”当我从命令行运行 m 文件时?

发布于 2024-11-24 02:53:58 字数 466 浏览 1 评论 0原文

我使用如下命令行字符串运行 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:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你在看孤独的风景 2024-12-01 02:53:58

如果您是从 Windows 上的另一个程序运行 Matlab,则可以使用 Matlab COM 自动化服务器。 ActiveX 控件有一个 Visible 属性,可以让您使命令窗口不可见,但看起来它使绘图可见。

下面是如何使用另一个 Matlab 作为控制器来完成此操作的示例。

ml = actxserver('Matlab.Application');
ml.Visible = false;
ml.Execute('surf(peaks)');

或者在 VBScript 中。

Set ml = CreateObject("Matlab.Application")
ml.Visible = false
ml.Execute("surf(peaks)")
ml.Execute("pause(4)")

无论如何,这种交互模式可能更符合您的需求,具体取决于您的工作流程的结构,因为它可以让您启动一次 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.

ml = actxserver('Matlab.Application');
ml.Visible = false;
ml.Execute('surf(peaks)');

Or in VBScript.

Set ml = CreateObject("Matlab.Application")
ml.Visible = false
ml.Execute("surf(peaks)")
ml.Execute("pause(4)")

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 of surf(peaks). Your mfile.m will need some GUI logic that makes it block until the user dismisses the plot, replacing the pause call, so it doesn't disappear before they're done viewing it.

热血少△年 2024-12-01 02:53:58

好消息!

通过一些 Java 操作,这是可能的! 正常启动 MATLAB(通过桌面等)。现在运行 setDesktopVisibility (假)瞧!例如

setDesktopVisibility(false);
mesh(rand(10));
pause;
setDesktopVisibility(true);

,据我所知,您无法在 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.

setDesktopVisibility(false);
mesh(rand(10));
pause;
setDesktopVisibility(true);

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).

假面具 2024-12-01 02:53:58

运行:

matlab -automation -wait -r "cd \'...\';..."

,这将在用户会话中显示最小化的窗口。根据Amro的建议,我们可以将最小化的窗口发送到本地的winlogin会话,这样我们就看不到最小化的Window:

psexec /i 0 matlab -nodesktop -wait -r "plot(rand(100,1)); print -dpng out.png;quit" >null 2>&1

了,它会默默地将图形保存到C:\Windows\System32(如果启用了ISD服务,可能会弹出一个交互式服务检测对话框窗口,并且 /s 或 /x 选项在 Windows Server 2003 或 2008 中不起作用。)

Run:

matlab -automation -wait -r "cd \'...\';..."

,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:

psexec /i 0 matlab -nodesktop -wait -r "plot(rand(100,1)); print -dpng out.png;quit" >null 2>&1

,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.)

魂ガ小子 2024-12-01 02:53:58
com.mathworks.mde.desk.MLDesktop.getInstance.closeCommandWindow

您可以从命令行使用它:

-r "com.mathworks.mde.desk.MLDesktop.getInstance.closeCommandWindow; run('C:\<a long path here>\mfile.m');"
com.mathworks.mde.desk.MLDesktop.getInstance.closeCommandWindow

You can probably use it from the command-line as:

-r "com.mathworks.mde.desk.MLDesktop.getInstance.closeCommandWindow; run('C:\<a long path here>\mfile.m');"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文