How to check in which step MATALB code is running?
65 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(4 个)
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.
0 个评论
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.)
0 个评论
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
2022-9-4
https://www.mathworks.com/matlabcentral/fileexchange/22161-waitbar-with-time-estimation even does time estimates
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!