MATLAB: Way to tell % complete of script

live script

Is there a way to get an elapsed time or estimated time left or even a percent left of a script that is running?

Best Answer

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