MATLAB: Can I run matlab’s command windows in win10’s cmd??

batchcommand windowsterminal

I am running a matlab file using -batch command on windows cmd.
At first, I type this on cmd
matlab -nosplash -nodesktop -minimize -r file_name
and I don't want matlab's command windows to show.
Then I type this
matlab -batch file_name
but the plot suddenly disappear.And i also try this
matlab -batch "file_name; pause( sec )"
but it only exsist for only a few seconds.
Is there any solution that I can directly get into matlab's command windows like this vedio
, or without losing my plot after I run command???( in win10 2020b)

Best Answer

The plot is going to disappear as soon as the MATLAB process exists. To keep the plot around indefinitely, you need to keep MATLAB from exiting.
Some ways you can do that include:
  • use uiwait() or waitfor() to wait for the figure to be destroyed
  • use pause() with no time (just pause by itself) to have MATLAB wait until a key is pressed -- but the key would have to be pressed in the command window and you do not want there to be a command window
  • use the Automation Interface to talk to MATLAB from a different program
  • In a different program use a .NET call to start MATLAB; you can send commands to the MATLAB session, eventually telling it to quit. Or just use .NET to start the process because you want to be able to kill the process easily