How to check in which step MATALB code is running?

조회 수: 117 (최근 30일)
Ketan
Ketan 2014년 8월 25일
댓글: Walter Roberson 2022년 9월 4일
I have made a code which took approx 4-5 hours to execute.....So how could I know on which step that code is running and how much time will it take to complete ?
  댓글 수: 2
Hyderkkk
Hyderkkk 2022년 9월 3일
ctrl+c in commend window
Walter Roberson
Walter Roberson 2022년 9월 3일
control-c will abort the execution!

댓글을 달려면 로그인하십시오.

답변 (4개)

Star Strider
Star Strider 2014년 8월 25일
Without seeing the code it’s impossible to say exactly. However when I run long simulations (usually with at least one loop), I start a time counter with the clock function at the beginning of the program (before the start of the loop), and just prior to the ends of the main loop, I put an fprintf statement that reports what the loop counter is, uses the etime function to show how long that loop took, and another calculation of how long the entire program has been running. All that prints in the Command Window. One fprintf statement like that doesn’t slow the code down noticeably, but it can be reassuring.

Ben11
Ben11 2014년 8월 25일
You might also want to look into dbstack, which tells you the actual line of code being executed.

Walter Roberson
Walter Roberson 2022년 9월 3일
At some point after 2014, if you happened to have an editor window open to something executed by the code, it became possible to set a breakpoint even though the code was already running.
If I recall correctly, while you are running you cannot use the editor ribbon to browse files to bring up your code if it was not already open (though I think it is sometimes possible if the file is on the Recent list.)

John D'Errico
John D'Errico 2022년 9월 3일
I tend to use things like waitbars, or some informative output that gives me a clue. For example, I have been recently running a massive set of computations recently, but there are intermediate points where I can efficiently update a waitbar. And while waitbars themselves can be costly, IF you update them thousands or millions of times, in my case, the waitbar is typically updated only a few dozen, or at most a few hundred times. And even better, I can even predict the amount of time that will be needed to complete the result. The process tends to be weakly quadratic in nature, so I can have good estimates of the predicted time. This allows me to know if I should wait up, or just go to bed and expect a result the next morning.
The point being, use waitbars in creative ways. Or display a limited set of intermediate results when possible. This helps to convince you that the code is working as designed, and not stuck in an infinite loop.
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 9월 4일
https://www.mathworks.com/matlabcentral/fileexchange/22161-waitbar-with-time-estimation even does time estimates

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by