I have had to deal with this problem many times in my various roles at The MathWorks. This is what I do for the big pieces of MATLAB code:
- Back it up, maybe twice!
- Select all, Ctrl-I to smart indent
Select all, Ctrl-J to wrap comments
If I am feeling paper-based- Print all the files out, and get a set of highlighters- follow manually, highlighting long term variables and important function calls.
~~~ AND / OR ~~~
5 If I am feeling lucky, start running the code in the debugger, stepping through
one line at a time (stepping into subfunctions that were user written)
At this point, I can go through and follow a typical flow through the control structure. I may not have a great idea what everything does, but I have a decent idea of what is going on.
Normally, my goal is to find a bug, solve it and move on. Your goals might be completely different. This is the method that I have used to quickly comprehend hundereds of different pieces of MATLAB code that I have been sent over the years.