by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 4.7, Creation date: 2019-06-22, Last change: 2025-09-14
showprogress(i,n,[dv])
i: | current index | |
n: | maximum index number | |
dv: | optional step size; default is 5; |
for i=1:200; showprogress(i,200); pause(.01); end; % Default step size
for i=1:200; showprogress(i,200,3); pause(.01); end; % 3 % Step size
This function, showprogress, is designed to display a progress indicator in the console during the execution of a loop or a long-running process. It provides feedback to the user by showing the percentage of completion in increments defined by the user or by default.
dv to the third argument; otherwise, set dv to 5.curc, nam, finish, and fstring.i is 1, initialize curc to 0, finish to false, and retrieve the caller function's name using dbstack. Set nam to the caller's name and prepare the initial format string fstring.i is greater than n, set n to i to handle cases where the loop might exceed the expected maximum.(i/n)*100 and check if it exceeds the last recorded progress by at least dv percent. If so, update curc and append the new progress percentage to fstring, then print it to the console.i is 0 or greater than or equal to n and finish is false, delete the progress text from the console by printing backspaces and set finish to true.