Clear Filters
Clear Filters

Is it possible to automatically comment few lines of matlab code after sometime while the code is running ?

3 views (last 30 days)
Is it possible to automatically comment few lines of Matlab code after some time while the code is running? I think this will save execution time of my code, because I don't want Matlab to check 'if' condition everytime in a for loop once it is true.
Please help.

Accepted Answer

Guillaume
Guillaume on 15 Jun 2017
No, it is not possible to modify code while it is running.
Unless your if expression is extremely complex, I wouldn't even worry about it. It's unlikely to be a bottleneck. And if it is a worry, the first thing to do is check that it is indeed a problem using a profiler.
If the if check is expensive you can always shortcircuit it:
checkpassed = false;
for ... %some loop
if checkpassed || someexpensivecheck
checkpassed = true;
%...
end
end
because of the shortcircuiting behaviour of ||, once checkpassed is true, someexpensivecheck is never run.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!