How can a process bar/wait bar run during a function is running

Hello, am running a code and I want to add a waitbar during a function is running, this function takes a lot of time but the problem is that the waitbar is updating after the function execution.
Here is the code:
h = waitbar(0,'Please wait...');
x1= ode3(F,tspan, xi');
for step = 1:0.008:time
waitbar(step /time)
end
close(h)

 Accepted Answer

Think twice: How can the waitbar get information about the current level of progress? Therefore it must get data from inside your ode3(). So insert the code for updating the waitbar inside this function. If this is not possible, e.g. because it is an external or built-in function, all you can do is to display a static message, which informs the user about a long running process.
If "ode3" means one of the built-in integrators, the OutputFcn ist a good choice: There you have the current value of the time. This need not be proportional to the elapsed time, but it is a rough hint about the progress.

1 Comment

Thanks a lot. I updated the waiitbar inside the ode3 function and is working now.

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!