waitbar or progress bar without using for loop

14 次查看(过去 30 天)
Hello everybody,
In my code, I have to call different number (it varies regarding to the user input in the GUI of the code) of data set from a sql data bank. Some times it could take 2 min or 5 min. most of suggestions in Answer segment or file exchange were reagrding to the application of waitbar in a for loop. But, there isn't any for loop im my code.
I tried to use tic, toc functions. Before calling the first data, I wrote 'tic' and after each call of sql data 'toc'. But I need the final performed time, which is unknown before finishing the whol process, to make a time fraction. Does anyone have a suggestion?
other question: if illustation of remaining would not possible for the described case, how can i show the preformed time after each Call of data set through a processbar. I mean:
tic;
call the first data set;
toc;
show the time in waitbar
call the second data set;
toc
show the time in the same waitbar
...
call the nth data set;
toc
show the time in the same waitbar
  4 个评论
Mahdi
Mahdi 2016-7-4
@José-Luis: because the user want to see the required time for each calling. Actually he want to know how,long should he wait for calling all required data.
José-Luis
José-Luis 2016-7-4
Well, if you know the number of datasets you will be loading you can give an estimate using the average of the time it has taken until now.
You could probably make that prediction more accurate using the size of the files you are loading. Looking at a file's size might be considerably faster than loading it to memory.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2016-7-4
"waitbar() creates a figure. In R2016a (did not check other HG2 implementations), that figure has a hidden member in Children which is a JavaWrapper . That JavaWrapper has a JavaPeer which is a javax.swing.JProgressBar which is what is doing the real work."
wb = waitbar(0, 'Your Message Here');
wbch = allchild(wb);
jp = wbch(1).JavaPeer;
and jp will be the javax.swing.JProgressBar
That JProgressBar has a method setIndeterminate . If you set it true
jp.setIndeterminate(1)
"An indeterminate progress bar continuously displays animation indicating that an operation of unknown length is occurring"
However...
"Some look and feels might not support indeterminate progress bars; they will ignore this property. "
It looks like my OS-X system is not animating the progress bar... or I missed something in the implementation.
  3 个评论
Othmane ELMOUATAMID
Thank you Walter for your answer, this helped me to create an indeterminate progress bar for Matlab 2016b.
I used it this way to keep the user away from Command Window while my code is running in the backgroud :
wb = waitbar(0, 'Pease wait ...','WindowStyle', 'modal');
wbch = allchild(wb);
jp = wbch(1).JavaPeer;
jp.setIndeterminate(1);
% ====== %
% my code here
% ====== %
close(wb);
Just in case someone needed it.
I found in the documentation that Maltab 2020a provides that in a easy way uiprogressdlg.
Saripaka Venkata Sai Prasanth
Thank you Othmane Elmouatamid.
I had been trying for this implementation and it helped a lot.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Dialog Boxes 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by