In the programming industry, the execution times of codes are very important. This is very important in terms of the efficiency of codes that are created. You can create codes that make iterations or other laborious operations by using your computer’s sources.
So, you may want to see the total time that is take in the execution of codes. You can do it in Matlab by using the ‘tic-toc’ code. Here, we will give a very basic example of the use of tic toc code in Matlab.
>> tic for a = 1:1000 a/2; end toc Elapsed time is 0.004508 seconds. >>
We have a very basic for-end loop that is created with 1000 elements. So this loop includes 1000 loops. Consider a situation that we want to measure the time is taken to execute this code.
We just typed ‘tic’ at the head of code and ‘toc’ and the foot of code. So, Matlab will measure the total execution time between ‘tic’ and ‘toc’.
You can see the result in the command window that it took 0.004508 seconds to execute this 1000 loop in Matlab. Quite fast right…?
The execution time of code also depends on the performance of the computer.
YOU CAN LEARN MatLab IN MECHANICAL BASE; Click And Start To Learn MatLab!
Do not forget to leave your comments and questions below about the use of the tic-toc command to measure code execution time in Matlab.
Your precious feedbacks are very important to us.