NO. You do NOT want to comment out code programmatically. That will NOT be faster, even if you can find a way to do it. Your promatically modified code will now become incredibly slow. (And probably buggy too.) And you want to do this a billion times? Sorry, but you need to learn MATLAB better, learning to write efficient code. But this approach you think you want is NOT the solution.
For example, a simple re-arrangement of your code will perform the test on flag only once for each flag.
It is possible that better code yet (that understands what the various algorithms are) may be eble to completely replace the loops, or at least partially replace them.