How to gracefully terminate continiuous script?

조회 수: 11 (최근 30일)
Jostein Holmgren
Jostein Holmgren 2017년 10월 25일
답변: Jos (10584) 2017년 10월 25일
I have a script which takes real-time input from an external device. The script begins with establishing a connection to this device, then does some real-time data processing and ends with shutting down said connection. I would like to be able to gracefully terminate the script by user input, that is have the script stop what it's doing, run the shut-down procedures before terminating completely. Currently, I can press ctrl+c to terminate the program, but this causes errors on subsequent attempts to reconnect to the device.

답변 (2개)

Rik
Rik 2017년 10월 25일
What I have done in a GUI is adding a button that is only visible when a callback is active. Each iteration of the loop I first check if the button has been clicked, if so, I exit the loop.

Jos (10584)
Jos (10584) 2017년 10월 25일
Rik provided a nice solution. If you do not have a GUI you might be able to use my STOPLOOP function in your code (which creates a very simple GUI itself): https://uk.mathworks.com/matlabcentral/fileexchange/20455-stoploop--v1-0--jun-2008-

카테고리

Help CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by