is there a way in MATLAB to compare the execution time of different functions or commands? For example I want to know how long does it take for MATLAB to execute n=1:5;sum(n) versus if I use a loop
U can but it’s just readability. Maybe you want to change the value of n or something. Maybe 1:5 is used more than once so it could be easier just changing it once and it would be updated for the whole code block
The idea is to show you how in-built functions such as sum are programmed by Matlab's designers. In this part, you need to imagine it as if you are the programmer who is creating the sum function itself so that users can use it directly. I know that it's kinda unclear, but when you take functions later on, you will understand what I mean.