Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I hide "MATLAB Command Window" when I run an m-file from command line?

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

like image 280
hkBattousai Avatar asked Jul 16 '11 13:07

hkBattousai


People also ask

Which command will be used to suppress and hide the MATLAB output for an expression?

1) To disable the display of any figure windows you can use the MATLAB startup option "-noFigureWindows".

Which command will only clear the Command Window and not the workspace window MATLAB?

Description. clc clears all the text from the Command Window, resulting in a clear screen.

How do I put the Command Window below in MATLAB?

On the Home tab, in the Environment section, click Preferences. Select MATLAB > Command Window, and then adjust the options as described in this table.


2 Answers

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.

like image 76
Andrew Janke Avatar answered Nov 15 '22 07:11

Andrew Janke


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

like image 29
Jacob Avatar answered Nov 15 '22 06:11

Jacob