Does Ctrl+C interrupt after executing all commands in a line?

2 次查看(过去 30 天)
Dear community,
I am running a loop where some state variables are updated.
Sometimes I want to interrupt that loop using Ctrl+C, but I want to make sure that all my state variables have been updated for consistency.
Currently I have created a structure that embeds all my state variables that I update writting:
state = state_past;
The intent is to update all the structure content at once, making it unafectable by a Ctrl+C interruption.
Q1: Do you think updating a whole structure is not interrupted by Ctrl+C?
Rather than using this state structure approach, I was thinking to write all my updates on the same line this way:
t = t_past; x = x_past; y = y_past; % and so on...
Q2: Do you think Ctrl+C can not interrupt in the middle of this line?
Q3: Is there a way to make sure a complete bloc of code is executed together not being interrupted by Ctrl+C?
Thank you for your enlightments.

采纳的回答

Adam Danz
Adam Danz 2020-10-21
编辑:Adam Danz 2020-10-23
Q1 & Q2 & Q3: No.
If ctrl+c is pressed before that line is executed or perhaps even while that line is executed it will be interrupted. If ctrl+c is executed afterwards the function will not return outputs. https://www.mathworks.com/help/matlab/matlab_env/stop-execution.html
Besides, this is a horrible design strategy. If you want the user to stop execution you can build in some flag-checks that check the status of a flag to decide whether to continue or not. The flag can be a property value such as a state button or something the user can control while the code is running. If the flag is false, for example, the functions can all terminate ('return'). Here's an example.
But see this disucssion, first (it's relevant whether you're using app designer or not).

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Objects 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by