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

waitbar

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)

Best 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.
Related Question