Interrupt execution of script, function or MATLAB expression after specified period of time. Similar to timeout from GNU coreutils.
This function uses undocumented command window method to programatically send Ctrl+C after specified period of time.
There are other ways of sending Ctrl+C programmatically, including Java Robot or SIGINT on Linux, but they require changes to the script or function that we want to interrupt.
This submission serves as a PoC and demonstration. Adapt to your specific needs if necessary.
Run the 'longComputations' script for no more than 5 seconds:
Interrupt execution of infinite pause after 3 seconds:
Mikhail (2022). timeout (https://www.mathworks.com/matlabcentral/fileexchange/61263-timeout), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!