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

조회 수: 1 (최근 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