필터 지우기
필터 지우기

Waiting for a Timer object to compelte a Task

조회 수: 9 (최근 30일)
Jan
Jan 2011년 7월 12일
Hi,
I have a timer that runs indefinitely in background. It is incrementing a global variable, x, from 0.
Outside of the timer object, on the GUI, the user may press a button, resetting x to 0. I would like the user to wait (hang) until x > 10, at which point a message would pop up.
Is there a way for me to wait until the Timer object completes its task and check if x > 10 after each Timer task execution?
I basically want to wait for the timer to complete 10 times before I execute further code in the callback function the user triggered.
Thanks in advance.

채택된 답변

Walter Roberson
Walter Roberson 2011년 7월 12일
Instead of using a global variable, use the UserData property of the timer object, and use waitfor() to wait until the UserData property has the value you want; see http://www.mathworks.com/help/techdoc/ref/waitfor.html
  댓글 수: 3
Walter Roberson
Walter Roberson 2011년 7월 12일
You could use the UserData property of any graphics object that exists when you create the timer object. Including of the button. You just have to pass the handle in as part of the timer object callback... or you could set the Tag on the object and findobj() it in the timer callback (though that would be less efficient.)
Jan
Jan 2011년 7월 13일
I used the 'UserData' property on the button, and used the waitfor(button, 'UserData', 10) as the condition.
Everything works. Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Paulo Silva
Paulo Silva 2011년 7월 12일
b=uicontrol('Style','pushbutton','callback',@pbcallback...
'String','reset x','Position',[315,180,70,25]);
set(b,'enable','off')
In the timerfcn callback test the value of x
if x>10
set(b,'Enable','on')
%now the user can press the button
end
Replace the handle b by the handle for your pushbutton and make the function callback of the button so it can put x=0

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by