Way to tell % complete of script

15 次查看(过去 30 天)
Is there a way to get an elapsed time or estimated time left or even a percent left of a script that is running?

采纳的回答

Jan
Jan 2011-8-17
The elapsed time is easy:
iniTime = clock;
for i = 1:1000
... your calculations here
pause(0.02); % For demonstration only
fprintf('elapsed time: %d sec\n', etime(clock, iniTime));
drawnow;
end
Estimating how long the processing will run, needs additional knowledge about the calculations. In the example all iterations of the FOR loop will use a similar amount of time. But if you use "pause(rand*1000)" there is no chance for a fair estimation. Then only showing the percentage of remaining iterations is meaningful.
If your script is not based on a loop, other messages might be helpful:
fprintf('Initialize... ');
pause(0.5);
fprintf('ready\n');
fprintf('Processing stage 1... ');
pause(0.5);
fprintf('ready\n');
... etc

更多回答(2 个)

David Young
David Young 2011-8-17
If the script is already running, no.
If
  • the script has not yet started running
  • you can identify the main loop
  • each iteration of the loop takes a reasonably consistent length of time
  • the total number of iterations of the loop is known in advance
then you can insert a statement in the loop to print out the percentage of iterations complete, or display a progress bar using waitbar. There are examples in
doc waitbar
To get the elapsed time, you can use tic and toc. To get the cpu time used, you can use cputime.

Daniel Shub
Daniel Shub 2011-8-17
If you have not started the script yet, but want the script to tell you how far you are along once you start it there are a number of submission on the FEX: http://www.mathworks.com/matlabcentral/fileexchange/?term=progress+bar
If the script is already running, then in general you cannot find out where it is. If you have a good idea of what the memory/processor/network profile should look like, then maybe you could inspect those and figure out where you are.

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by