Ctrl-C in Matlab R2023b not working well

9 views (last 30 days)
Jim Svensson
Jim Svensson on 11 Mar 2024
Commented: Jim Svensson on 25 Mar 2024
When running Matlab in Window the keyboard combination Ctrl-C has previously worked well to abort execution of a running matlab program/script/function, and to return to the command window.
In Matlab R2023b this does not work well in several cases. Some specific cases include
  • Iterating over multipel matlab.unittest.TestCase tests.
  • Iterating in loops calling linprog() solvers.
Overall it seems that in loops and similar iterations Ctrl-C does not work well to abort the current execution.
Question: Is the how it is supposed to be now? Is there something that can be configured to make it work better as before?
Version R2022b does not have this issue. I don't know about R2023a.

Answers (1)

Vandit
Vandit on 22 Mar 2024
Hello Jim,
As mentioned in the MATLAB documentation Stop Execution - MATLAB & Simulink (mathworks.com), Ctrl+C might not always effectively stop execution for scripts or functions that run for an extended duration or that call built-ins or MEX-files. This is due to the potential risk of leaving MATLAB in an inconsistent state or not properly releasing native resources, like memory, which are shared with MEX files within the same memory space as MATLAB.
To mitigate this issue and enhance the interruptibility of your MATLAB scripts or functions, it is recommended to incorporate a "drawnow", "pause", or "getframe" function within your file, especially if it contains large loops. These functions can provide MATLAB with the opportunity to process the interrupt request more effectively.
To know more about "drawnow", "pause" and "getframe" functions, please refer to the links given below:
Hope this helps.
  1 Comment
Jim Svensson
Jim Svensson on 25 Mar 2024
Thanks for the suggestion. I will add some of those calls and see if it helps.

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!