How to hide the "MATLAB command window" when running m file from the command line?

I run MATLAB with a command line 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 the plot() function for constructing a simple curve on the xy plane.

The m file successfully starts and draws a graph with the above command line. However, every time I run this command, a window called “MATLAB Command Window” appears along with the graphics.

How to make this "MATLAB command window" is NOT displayed, so only the image will be displayed.

The MATLAB Command Window is as follows: enter image description here

+6
source share
4 answers

Great news!

With a bit of Java manipulation, it's possible! Start MATLAB normally (from the desktop, etc.) Now run setDesktopVisibility (false) and voila! For instance.

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

AFAIK you cannot do this on Windows using parameters with matlab.exe . If you really need to hide this, I would recommend using the MATLAB Engine to display your figure. In addition, if for simple things, such as plotting, etc., you can use GNU Octave , which works with M files and does not have a “command window”, for example, MATLAB (it works on the Windows command line and hides it not so difficult).

+3
source

If you use Matlab from another program on Windows, you can start it using Matlab COM Automation Server . The ActiveX control has a Visible property that allows you to make the command line window invisible, but it looks like it leaves visible graphics.

Here is an example of how to do this using another Matlab as a 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 may be more than what you want in any case, depending on how your workflow is structured, because it will allow you to start the Matlab process once and make a lot of mailing requests on it, saving startup costs and letting you have multiple graphs visible at once.

If you still want to call it from the command line, just run it using the .vbs shell script with the above VBScript code, but call run('...\mfile.m') instead of surf(peaks) . Your mfile.m will need some GUI logic that blocks it until the user dodges the graph, replacing the pause call so that it does not disappear before they look at it.

+3
source

Run:

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

which will show a minimized window in a user session. At the suggestion of Amro, we can send a minimized window to a winlogin session locally so that we cannot even 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 automatically save the number in C: \ Windows \ System32 (if the ISD service is enabled, it may open the dialog box for detecting interactive services and / s or / x may not work on Windows Server 2003 or 2008.)

+2
source
 com.mathworks.mde.desk.MLDesktop.getInstance.closeCommandWindow 

You can probably use it from the command line like:

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

Source: https://habr.com/ru/post/892895/


All Articles