Matlab gui: grayed out button not working properly

8 Ansichten (letzte 30 Tage)
JS
JS am 3 Dez. 2013
Kommentiert: JS am 3 Dez. 2013
Hello everybody,
I have a strange problem. I want that some buttons are grayed out when doing a computation. In my button1_Callback I placed the following code:
set(handles.button1,'Enable','off');
set(handles.button2,'Enable','off');
set(handles.button3,'Enable','off');
pause(0.1)
%... doing a calculation which plots a function (total time a couple of seconds)
set(handles.button1,'Enable','on');
set(handles.button2,'Enable','on');
set(handles.button3,'Enable','on');
Like you can notice, I need to add the line pause(0.1) otherwise the code won't work. The buttons will become unclickable during the computation but not grayed out.. I tried everything but only adding this little pause will make the buttons grayed out during the computation. Somebody any idea on what's going on? It doesn't look normal that I need to add the little pause.
Thanks,

Akzeptierte Antwort

Image Analyst
Image Analyst am 3 Dez. 2013
MATLAB races ahead and gets all tied up in doing some intensive computation that it thinks is more important than processing the message to repaint your display. Putting in a pause allows it that time, but a better option is to put in a "drawnow" instead of the pause():
drawnow
This will force the operating system to repaint/refresh/update your GUI display before continuing on with the subsequent code.
  1 Kommentar
JS
JS am 3 Dez. 2013
Ok, thank you very much for the explanation, it works. And the drawnow looks better than the pause(0.1).

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by