MATLAB: How to stop for-loop outside of the loop

for looptermination

Hello,
I have the below simple code.
It displays a counter of seconds.
How can I stop it with a command? NOT by pressing Ctrl+C?
I am not asking about the break command. Sometimes I want it to finish to count all the seconds, and sometimes I want to terminate it in the middle. For now I'm using Ctrl+C. I was wondering if there is a more elegant way.
THANK YOU!
for t = 1:timeDuration
disp(['Elapsed time ' num2str(t) ' seconds']);
pause(1);
end

Best Answer

Sounds like you want a GUI of a stop watch.
https://www.mathworks.com/matlabcentral/fileexchange/12628-stopwatch
Related Question