When you click Ctrl C, MATLAB interprets it as an interrupt. I don’t think there is a way to catch the call and do something like switching to another cycle or so, for example.
However, you can use the function onCleanupto perform operations, such as closing open files, deleting temporary files, recording a log, displaying a message, or even saving a workspace until MATLAB is interrupted. However, it must be called from within the function.
Here is a simple illustrative example.
function test
currentDir=pwd;
cd 'path to some folder'
c=onCleanup(@()cd(currentDir));
for i=1:...
%
end
So, when this function starts and you interrupt it, it returns you to the same folder that you were in when you ran it. It's nice that you are not stuck in some random folder, and you need to enter manually every time.
abcd source
share