set enable propeprty to off

조회 수: 11 (최근 30일)
antonis
antonis 2013년 11월 1일
댓글: antonis 2013년 11월 1일
In a gui i have a button which executes a simulation that lasts ~ 20sec. During this period i want the button to be disabled, so i have written in buttons callback:
set(hObject,'Enable','off'); simulation(); set(hObject,'Enable','on');
It doesnt work. It seems that that the set method operates after the end of simulation because if i write set(hObject,'Enable','off');simulation(); the button is disabled after the simulation finishes!!!
Why please?

답변 (2개)

Doug Hull
Doug Hull 2013년 11월 1일
You might want to put a DRAWNOW before simulation. It could help to ensure the GUI is updated before simulation is called.

Image Analyst
Image Analyst 2013년 11월 1일
Call drawnow to force an update/refresh/repaint:
set(hObject,'Enable','off');
drawnow;
simulation();
set(hObject,'Enable','on');
The problem is that it got into your intensive simulation right away before the message to gray out your button was processed. Basically it sends a message to the operating system to disable that button, and the operating system can decide when it wants to act upon that message. But meanwhile your MATLAB script barrels on doing your simulation and the operating system thinks that is a higher priority process so it does that first and will get around to disabling your button whenever it thinks it has time to do so. Calling drawnow forces it to do that right away before it can move on to the next thing.

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by