But today, it shall be on a programmers requirement. During the process of actually writing code [not downloading and running it :)] one may encounter errors. Probably with dimensions, etc.
The keyboard command is a simple way to stop the execution and give the coder a chance to check the values on the MATLAB command window whose cursor turns to a K>> or even write different code from that of the execution sequence. Its especially useful in functions in which we generally have no chance of seeing what exactly are the values of the internally used variables. return continues with the normal execution with updated variables (if any).
Another similar function is the dbstop which adds a bit more functionality. Typically useful is the set of “dbstop if …” commands of which dbstop if error stops and gives you power to debug (db) only in case you encounter an error. dbcont continues, dbquit exits, dbstep moves to the next execution, etc.
This can be also achieved in the Editor by clicking on the horizontal line and making it a red ball which inserts a breakpoint and then using the icons of step which carries a line of execution, step in which goes in the function (in case its a function), step out which comes out of that function or finishes in case its the main or continue to continue and exit debug.
In fact even to understand downloaded code, its nice to let it execute step-by-step and see how the variables are changing to get an insight into it.
Coming up with a lot more Matlab tricks soon. 🙂