The title pretty much says it all. When I profile some code, I notice that the "end" statement of a for loop has non-trivial amounts of execution time. That seems odd to me.
Matlab checks after every line, if Ctrl-C was pressed (usually...). Going line-by-line through the code using the debugger needs the infmormation about the lines also. Therefore even an end needs some execution time.
Well, this is a pure guessing. What about my 2nd theory:
end is converted implicitely to a goto. This consumes time.
There is some overhead for changing the loop variable to the next value. That overhead would normally be small for a regular for loop, but would be higher for a "for" over a matrix such as
for K = rand(3,5)
More likely, though, you are probably seeing JIT effects.
Play games and win prizes!Learn more