Why is Ctrl-C inconsistent in breaking out of loops in MATLAB 7.0 (R14)?

2 views (last 30 days)
I have a MATLAB file function or script that executes a loop many times. When debugging the application, I occasionally need to stop execution before it completes all the iterations of the loop. In MATLAB 6.5 (R13) and earlier versions, Ctrl-C consistently stopped execution of MATLAB functions. In MATLAB 7.0 (R14), Ctrl-C seems to work less frequently.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 1 Sep 2009
Pressing Ctrl-C while MATLAB is performing a computation adds to a pending event queue. This queue is not necessarily processed during each iteration of a loop, which leads to the behavior where Ctrl-C does not appear to affect program execution. Insert DRAWNOW in the loop to force MATLAB to process the event queue at each iteration of the loop, even if your program does not generate any figures. This will ensure that the event queue is processed at each iteration of the loop when DRAWNOW is called. An example of how to use DRAWNOW is shown below:
for i = 1:10000
j = i^2;
drawnow;
end

More Answers (0)

MathWorks Support

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!