When running script from command line, how to close Matlab after?

I have a script that I will be running from the command line, inside Windows 7 Scheduled Tasks. After the script completes, I need Matlab to quit/close. Presently the script is run as "C:\Program Files (x86)\MATLAB\R2011b\bin\matlab.exe" -r myfile
Is there an additional Matlab flag that would command Matlab to close after myfile is done?

 採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 10 月 4 日

1 投票

Can you add quit or exit at the end of your myfile.m ?
or
matlab.exe -r myfile;quit

7 件のコメント

Walter Roberson
Walter Roberson 2011 年 10 月 4 日
Close, but you will almost certainly need to supply quotes. Also it is a good idea to put in a try/catch in case something goes wrong:
matlab -r "try;myfile;catch;end;quit"
Fangjun Jiang
Fangjun Jiang 2011 年 10 月 4 日
try-catch is a good idea. However, I tried. It works without the quotes.
K E
K E 2011 年 10 月 4 日
I put quit inside myfile.m
Walter Roberson
Walter Roberson 2011 年 10 月 4 日
I recommend that the rest of your functionality be in a try/catch block, just in case something bombs out for some reason. You want to be _certain_ that the quit is executed.
K E
K E 2012 年 3 月 14 日
Thanks all! Appreciate the help.
Arun Badigannavar
Arun Badigannavar 2016 年 8 月 10 日
I am also doing similar kind of job,Where I am using exit at MATLAB script, But it is asking for the simulink models to save,(Though I have give save_system), So i am not able to close MATLAB, Is there a way to Kill MATLAB from Dos Commands, So I can put it in a batch file
Fangjun Jiang
Fangjun Jiang 2016 年 8 月 10 日
Is it due to the fact that save_system() takes some time to finish thus the exit command can't be executed? A few suggestions:
1. Check the Simulink model status get_param(Model,'Dirty') to see if the model has been changed and then decide whether to save
2. Use save_system(Model, false) to close the model without saving if possible
3. Use pause() to add a delay before quit.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

質問済み:

K E
2011 年 10 月 4 日

コメント済み:

2016 年 8 月 10 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by