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

3 次查看(过去 30 天)
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.

采纳的回答

Guillaume
Guillaume 2017-6-15
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by