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

2 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Adam Danz
Adam Danz il 21 Ott 2020
Modificato: Adam Danz il 23 Ott 2020
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).

Più risposte (0)

Categorie

Scopri di più su Graphics Objects in Help Center e File Exchange

Tag

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by