GUI waitbar and script execution

8 次查看(过去 30 天)
ingeln91
ingeln91 2017-9-7
Hello everyone ! I've go a very simple matlab GUI with a push button that execute a .m file. I need to insert a waitbar that show the .m file execution percentage. For example, like i run "nlfilter" function.
Thank you everyone !
  8 个评论
Rik
Rik 2017-9-7
Of course you are not wrong, it just depends on what you mean with the word useful. Accurate in terms of timing is almost never possible, but accuracy in terms of number of steps left is often possible. Waitbars are notorious for being only guestimates, so if you accept that, the way to use them is outlined in the comment by Stephen and my answer.

请先登录,再进行评论。

回答(1 个)

Rik
Rik 2017-9-7
The waitbar is simply a progressbar. You need to input the percentage yourself, usually it is best to do that at meaningful time intervals so you get an approximation of the time left. This is however not necessary.
h=waitbar(0,'Please wait, calculation in progress.')
%first piece of code
waitbar(0.5,h)
%sencond piece of code
waitbar(1,h,'Calculation done')%you can update the text
%close the waitbar
delete(h);
If you forget to close the figure during debugging or something, you can use these two lines to force a close:
set(groot,'ShowHiddenHandles','on')
delete(get(groot,'Children'))
So as long as you have access to the internal code of your function, you can generate and update a waitbar. For internal functions (or even worse: mex functions) you're stuck.

类别

Help CenterFile Exchange 中查找有关 App Building 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by