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.
0 个评论
采纳的回答
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!