MATLAB: Waiting for a Timer object to compelte a Task

timerwait

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.

Best Answer

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
Related Question