Borrar filtros
Borrar filtros

Create timing bar with specified duration

28 visualizaciones (últimos 30 días)
Ruaridh Purse
Ruaridh Purse el 27 de Feb. de 2022
Editada: Simar el 9 de Oct. de 2023
I'm having real trouble finding any examples of progress bar figures that update to completion over the course of a specified time. How do I do this? I see several functions that seem to estimate the time remaining for a given computation. I need a function where I can just specify some number of seconds over which a progress bar will elapse.
  2 comentarios
AndresVar
AndresVar el 27 de Feb. de 2022
Ruaridh Purse
Ruaridh Purse el 28 de Feb. de 2022
Thanks, that's a start-- I need to have other things running at the same time though! I'm specifically trying to make a timebar that experimental participants can see while they are being recorded.

Iniciar sesión para comentar.

Respuestas (1)

Simar
Simar el 5 de Oct. de 2023
Editada: Simar el 9 de Oct. de 2023
Hi Ruaridh Purse,
I understand that you are finding it difficult to find examples of progress bar figure that updates over a specific time. You can use the waitbar function in MATLAB. This function allows to display a progress bar that fills up gradually as time passes.
Please follow the below mentioned steps for implementing the waitbar” function:
  1. First, specify the total time (in seconds) that the progress bar should take to complete. Let's say in this case it should take 10 seconds to complete.
  2. Decide how often the progress bar should update. For example, it should update every 0.1 seconds.
  3. Next, create the progress bar figure using the waitbar function. You can give also it a message, such as "Please wait...", and a name for the figure, like "Progress".
  4. Calculate the number of updates needed by dividing the total time by the update interval. In the example, this would be 10 seconds divided by 0.1 seconds, resulting in 100 updates.
  5. Use a loop to update the progress bar. Inside the loop, use the waitbar function again to update the progress bar's value. Customize the message to show the progress as a percentage. After each update, pause the loop for the specified update interval using the pause" function.
  6. Once the loop is finished, close the progress bar figure using the close function.
Please refer to the example code below:
totalTime = 10; % Total time in seconds
updateInterval = 0.1; % Interval at which the progress bar updates (in seconds)
% Create the progress bar figure
h = waitbar(0, 'Please wait...', 'Name', 'Progress');
% Calculate the number of updates needed
numUpdates = totalTime / updateInterval;
% Loop to update the progress bar
for i = 1:numUpdates
waitbar(i/numUpdates, h, sprintf('Progress: %d%%', round(i/numUpdates*100)));
pause(updateInterval); % Pause for the specified update interval
end
% Close the progress bar figure
close(h);
Attaching a Screenshot of progress bar for reference:
Please refer to the documentation links for more details:
Best Regards,
Simar

Categorías

Más información sobre Dialog Boxes en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by