waitbar or progress bar without using for loop
14 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
José-Luis
il 4 Lug 2016
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.
Risposte (1)
Walter Roberson
il 4 Lug 2016
I recently described in http://www.mathworks.com/matlabcentral/answers/293374-waitbar-color-2016a-is-broken-red-how-to-set-to-older-continuous-green#answer_227433 that in R2014b and later:
"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)
and https://docs.oracle.com/javase/7/docs/api/javax/swing/JProgressBar.html#setIndeterminate(boolean)
"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 Commenti
Othmane ELMOUATAMID
il 13 Apr 2020
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.
Saripaka Venkata Sai Prasanth
il 4 Giu 2020
Thank you Othmane Elmouatamid.
I had been trying for this implementation and it helped a lot.
Vedere anche
Categorie
Scopri di più su Dialog Boxes in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!