Hi, you can use the "tic" and "toc" matlab functions, which ones let you to create a timer and control the elapsed time between the execution of a code, for example in your case:
tStart=tic;
for n=1:10e50
a=n+1;
tEnd=toc(tStart);
if(tEnd>=(2*60))
disp('It has spent 2min');
break;
end
end
tEnd has got the time elapsed in seconds, and 10e50 is a value I have set randomly to make the code spend more than two minutes. In the condition you can see I have set "2" minutes in seconds.
Regards!
Best Answer