2

I have a main function in MATLAB which consists of a while(1) loop. Also, I have subscribed to a ros image_raw topic which updates a callback function in MATLAB.

Whenever I press CTRL+C, I should hold it for a long time to work. I have tried onCleanUp but it is not working, either.

How can I quickly stop the program when running?

Setup: Windows10, MATLAB 2017b

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Bug_Free
  • 81
  • 5

2 Answers2

3

MATLAB responds to CTRL-C only at certain times. Lines of code in the MATLAB language respond immediately, but If you are calling into a library not written in MATLAB, then the CTRL-C will only take effect when control returns to MATLAB. (This applies even to some functionality shipping with MATLAB such as linear algebra routines which call our to external libraries like MKL).

Basically, there's probably not much you can do if the function you're calling doesn't respond immediately. You shouldn't need to hold down CTLR-C though, the request should be queued.

I don't think onCleanup is relevant here - that's for dealing with the effect of the CTRL-C.

Edric
  • 23,676
  • 2
  • 38
  • 40
0

Try Ctrl+Break (it may be Ctrl + Fn + Pause based on your keyboard). If that doesn't work, it may just be a computational limitation of MATLAB; my other suggestion would be running ROS in the Windows SubSystem for Linux (WSL) and running your subscriber in MATLAB, or move the ROS master and subscriber to the WSL and use python or another language for the subscriber.

AlgoNoob
  • 11
  • 2