MATLAB: Wait to execute commands

command windowtictimetoc

Hi, I am trying to write the following matlab code:
tic
for a=A
if (a==8)
disp('I found it');
break;
end
end
toc
but the moment I write tic in the command window it starts counting time, how can I tell matlab to start counting time only when the whole code in written?

Best Answer

tic will restart the counter whenever you run it. So you don't need to worry if you ran tic several times before. Just run it after you have finished your code, and it will count from that point forward.