progress indicator in GUI

2 ビュー (過去 30 日間)
Tobyn VanVeghten
Tobyn VanVeghten 2011 年 9 月 16 日
コメント済み: dominic diston 2018 年 9 月 26 日
Hey,
I have a GUI with a pushbutton. Depending on what the user previously selected, Matlab may take a few seconds to perform the task behind the pushbutton. I would like a simple indicator in the GUI that the pushbutton task is being performed and when it is done. I originally tried changing the pushbutton string to say "wait" during processing and then back to the original string afterwards. I did this with the following code:
name = get(handles.pushbutton, 'String');
set(handles.pushbutton, 'String', 'Wait');
do_whatever();
set(handles.pushbutton, 'String', name);
However, when I tried this, Matlab never updated the pushbutton string (at least, that I could tell). Is there a way to force Matlab to update the string before handling the next command? Or is there a better way to do this?
Thanks, Tobyn

採用された回答

Grzegorz Knor
Grzegorz Knor 2011 年 9 月 16 日
Try in this way (you can also add progress bar):
function test
uicontrol('Style','pushbutton','String','Start','callback',@pb_clbck)
function pb_clbck(src,evnt)
name = get(src,'String');
set(src,'String','Wait');
h = waitbar(0,'Please wait');
for k=10:-1:1
waitbar((11-k)/10,h)
disp(k)
pause(1)
end
close(h)
set(src,'String',name);
In this case Matlab refreshes strings.
Eventually you can use refresh function to redraw current figure:
name = get(handles.pushbutton, 'String');
set(handles.pushbutton, 'String', 'Wait');
do_whatever();
set(handles.pushbutton, 'String', name);
refresh(gcf)
  2 件のコメント
Tobyn VanVeghten
Tobyn VanVeghten 2011 年 9 月 16 日
Thanks! That should work well.
Tobyn
dominic diston
dominic diston 2018 年 9 月 26 日
Thanks for this. I've learned something new. Really useful for I'm doing right now.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDesktop についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by