MATLAB: Start script at a chosen line

debuggingpause

As we know it is not possible to modify a running script. You have to stop the script and restart it for the changes to become active. Now I wonder if it is possible to jump into a script at a chosen line. So one could stop a running process, make the desired changes and then have the program continue in the modified version without running the code before the changed part again.

Best Answer

Using a method to stop and re-enter scripts at arbitrary lines would be a meta-interpreter, which runs on top of Matlab. Such a method would be prone to errors and it will be hard to reproduce the results reliably. If you want to run a code with some modifications, create a function and trigger the different methods by using a switch, e.g. controlled by an input argument.
Using structured code and functions is such a great improvement and much more stable than running scripts in dynamically modified pieces, that I cannot imagine, why somebody wants to do it the hard and complicated way.