The debugger is thought for (guess what?) debugging. It is not a powerful tool to control the program flow. Maybe the observed behavior is a but, or it is intended. Modifying code during the the program runs, can have extremely strange side-effects, e.g. if a function calls itself recursively over a certain number of other functions. There is no chance to cope with such ambiguities reliably.
In addition, enabling the debugger (e.g. by setting breakpoints) disables the JIT acceleration. This is required, because the JIT can reorder the sequence of commands to improve the speed. But then stepping through the code line by line cannot work anymore. In consequence some code can be 100 times slower compared to a disabled debugger. Therefore it is a bad idea to use the debugger to modify the code while the program is running.
There are smarter and more efficient techniques, e.g. load the data into a persistent variable:
function Data = Storage
persistent Data_P
if isempty(Data_P)
Data_P = load(...
end
Data = Data_P;
end
Then you can call this function to obtain the data, but they are kept in the memory and the following calls will run much faster. This is much cleaner and more reliable than juggling with the debugger.
So my advice is not to use the debugger to control the program flow. Use code and persistently stored data to do this.
Best Answer