GUI waitbar and script execution

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

José-Luis
José-Luis 2017년 9월 7일
In order to insert a useful waitbar, you'd need a reliable way to predict how much time your function is going to take. Do you already have that?
ingeln91
ingeln91 2017년 9월 7일
No :( my .m file is an image processing script and the execution time is not fixed, but varying with the image(i.e. 0resolution etc...)
José-Luis
José-Luis 2017년 9월 7일
편집: José-Luis 2017년 9월 7일
Without knowing the details of your implementation, it is difficult to give concrete advice.
ingeln91
ingeln91 2017년 9월 7일
oh,ok :( thank you so much !
Stephen23
Stephen23 2017년 9월 7일
"I need to insert a waitbar that show the .m file execution percentage"
That is easy: open a waitbar at the start of your function, then update it at several points within the function.
José-Luis
José-Luis 2017년 9월 7일
I stand by my point.
How many times have we not had to wait hours (slight exageration) after the 99% complete?
It might be that those percentages, as representative of total time, are meaningless.
Adequate percentages in terms of timing require knowledge (or guesses) of how much time each function is going to take.
This can even be meaningless in a loop if it contains functions that will be evaluated only under certain conditions.
They are however indicative how far down in your code you have gone, which might be what OP wanted anyway. They'd be signalling "Hey, I'm still running" more than be indicative of actual percentage.
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.
José-Luis
José-Luis 2017년 9월 7일
Fair enough.

댓글을 달려면 로그인하십시오.

답변 (1개)

Rik
Rik 2017년 9월 7일

1 개 추천

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.

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

태그

질문:

2017년 9월 7일

댓글:

2017년 9월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by