How can I wait to work in Matlab?

I want to have a queue for an operation that takes quite a while. Here is my code:

h = waitbar(0,'Please wait...'); for i=1:counterend waitbar(i/waitbarcounter) Atemp = At+i*step; handle = @(M) 1/M^2*((2/(gamma+1))*(1+(gamma-1)*M^2/2))^((gamma+1)/(gamma-1))-(Atemp/At)^2; Mach = fzero(handle, 5); Aplot(i) = Atemp/At; Tplot(i) = Tc / (1+(gamma-1)*Mach^2/2); Mplot(i) = Mach; plot(Aplot, Tplot) end close(h) 

Matlab error gives:

??? Error using ==> waitbar in 249
Incorrect message bar arguments

After research, I am sure that this error should occur due to the environment code in the loop.

Note. The loop works fine without a message bar.

+6
matlab
source share
6 answers

Launch

 counterend = 10000; >> h = waitbar(0,'Please wait...'); for i=1:counterend waitbar(i/counterend) end close(h); 

Works as expected in 2007a / Windows XP.

On the other hand, it will help to find out what occurs as indicated. Something quick to check would be to make sure that you are not passing CELL to it.

Launch

 counterend = {10000}; h = waitbar(0,'Please wait...'); for i=1:counterend waitbar(i/counterend) end close(h); 

Another error loses (see below) in 2007a, but this error message may have changed in 2008.

??? Undefined function or method '_colonobj' for input arguments of type 'cell'.

My last tip will warn you about using the waitbar for large arrays / datasets. Although I think it’s important to keep the user informed about the progress, there is also a concern for me about how much time has been added to the loop. Working with arrays having 100k + entries, I became a religious Profiler user to find out where the time was really spent. I can say that the time is not in calculating i / X, it was all in updating the display of the standby panel. To mitigate the blow of the update / retraction, I only updated the message bar every 100-1000 entries, which helped a lot.

EDIT: Updated answer to match latest code

At first I started attacking this problem with anonymous functions, having problems with them in the past, this is a personal vendetta. When you studied the function, I found that you use the gamma, you define it as a constant (constant for the loop / function)? The reason I ask is because the "gamma" is a Matlab function and was giving me errors when trying to run your function on its own. Below I changed the code a bit, and everything works fine here. If any assumptions I made are wrong, please let me know. In addition, if you intended to use the gamma function, your function does not have any arguments. Hope this helps!

 clc h = waitbar(0,'Please wait...'); counterend = 1000; waitbarcounter = counterend; g_amma = 7; At = 34; step = 2; Tc = 42; for i=1:counterend waitbar(i/waitbarcounter) Atemp = At+i*step; handle = @(M) 1/M^2*((2/(g_amma+1))*(1+(g_amma-1)*M^2/2))^((g_amma+1)/(g_amma-1))-(Atemp/At)^2; Mach = fzero(handle, 5); Aplot(i) = Atemp/At; Tplot(i) = Tc / (1+(g_amma-1)*Mach^2/2); Mplot(i) = Mach; plot(Aplot, Tplot) end close(h) 

Hi,

Adam

+5
source share

I checked waitbar on R2008b. So far, the only ways I was able to reproduce your error was as follows: i/counterend evaluate an array with multiple lines (1x2 vector gives interesting results) and closing the front panel before calling waitbar(i/counterend) .

I have no error at startup:

 h = waitbar(0,'Please wait...'); counterend = 1000; for i=1:counterend waitbar(i/counterend) end close(h) 

Could you make sure that the example below works without errors? If so, check to see if the standby panel is closed during loop execution and that counterend is a scalar (use dbstop if error to stop code execution during an error).

If the above example does not work without errors, you should use which waitbar to verify that you are using the Matlab message bar and not any of the many updated versions from the Matlab file exchange file.

+3
source share

Performance

 counterned=1000; h = waitbar(0,'Please wait...'); for i=1:counterend waitbar(i/counterend) end close(h) 

works fine, as expected, on MATLAB R2009a in Windows XP.

+1
source share

The above works fine on the R2008a on XP as well.

However, you will get the error you described if you kill the waitbar window before the next waitbar command. If you want to be nice about this, you should check if the descriptor h valid before the waitbar .

+1
source share

I prefer to use the progressbar written by Steve Holzer on MATLAB FEX. I had no problems with this.

+1
source share

Suppose you use the handle that you created with the first line of code when you want to update the waiter, waiter (he / itmax, h, 'progress')

0
source share

All Articles