How to make a forced exit from Matlab with returning a code?

Hi all, I try to exit from Matlab in a script and want to return a code to the command line. I know that there is the command
exit(code);
to do that. But in my case, some unsaved Simulink files prevent me from exiting. That's why I use
exit force;
to exit from Matlab without beeing asked to save the file first. But this command does not allow to pass a code to the command line. I tried something like
exit(code, 'force')
But that didn't work. Any other ideas?
Thanks a lot, Ralf

回答 (2 件)

yusra Ch
yusra Ch 2018 年 10 月 26 日

1 投票

in the command window do this: ctrl+c and it will force the code to stop running

1 件のコメント

Ralf
Ralf 2018 年 10 月 29 日
Sorry, I need to exit from a Matlab script. I am not sitting in front of the PC when this (batch of) scripts run.

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

madhan ravi
madhan ravi 2018 年 10 月 26 日
編集済み: madhan ravi 2018 年 10 月 29 日

0 投票

exit %edited after sir Walter’s comment

7 件のコメント

madhan ravi
madhan ravi 2018 年 10 月 26 日
in command window
Ralf
Ralf 2018 年 10 月 29 日
How can I set an exit code using exit, leave?
madhan ravi
madhan ravi 2018 年 10 月 29 日
Try it in your script and experiment what happens
Walter Roberson
Walter Roberson 2018 年 10 月 29 日
編集済み: Walter Roberson 2018 年 10 月 29 日
There is no leave in MATLAB. There are exit and quit.
exit supports a return code but quit does not.
madhan ravi
madhan ravi 2018 年 10 月 29 日
編集済み: madhan ravi 2018 年 10 月 29 日
Ah Thank you sir Walter till date I had been using it together but didn’t looked into it so deeper though :)
Ralf
Ralf 2018 年 10 月 29 日
Thank you, Walter. But is there a way to combine an exit code with the force statement?
Walter Roberson
Walter Roberson 2018 年 10 月 29 日
It turns out that although the two are documented differently, they take the same options. However, only one option is permitted; it must be 'force' or 'cancel' or a scalar integer (negative values are permitted.) It is possible that there are additional undocumented options.

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

カテゴリ

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

製品

リリース

R2017b

タグ

質問済み:

2018 年 10 月 26 日

コメント済み:

2018 年 10 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by