Matlab gui: grayed out button not working properly
8 次查看(过去 30 天)
显示 更早的评论
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,
0 个评论
采纳的回答
Image Analyst
2013-12-3
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!