Matlab gui: grayed out button not working properly

14 views (last 30 days)
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,

Accepted Answer

Image Analyst
Image Analyst on 3 Dec 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 Comment
JS
JS on 3 Dec 2013
Ok, thank you very much for the explanation, it works. And the drawnow looks better than the pause(0.1).

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Objects in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!