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

前端 未结 4 2031
情歌与酒
情歌与酒 2020-12-18 06:35

I am running MATLAB with a command line string like this:

C:\\\\matlab.exe -nodisplay -nosplash -nodesktop -r \"run(\'C:\\

4条回答
  •  难免孤独
    2020-12-18 06:47

    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.

提交回复
热议问题