function to wait for a variable to change value

28 views (last 30 days)
waitfor(h,'PropertyName') as this syntax blocks the caller from executing until the value of 'PropertyName' (any property of the graphics object h) changes or h closes (is deleted), Is there any similar syntax that can suspend the command and wait until a variable changes its value?
Thanks!

Answers (1)

Walter Roberson
Walter Roberson on 21 Oct 2011
It took me a bit of time to come up with a mechanism by which such a situation could happen at all (if one leaves out parallel processing.)
In every case I have been able to think of, there has to be a callback involved (whether handle graphics or timer or serial object or the like.) Without parallel processing, callbacks are the only mechanism to (however temporarily) get a second thread going that can do independent work such as changing a variable. And if you are going to have a callback involved, one might as well wait on a graphics object property that stands proxy for the variable being changed.
For example, in various callbacks, one might have
set(0,'UserData','X71_Updated');
set(0,'UserData','Theta_Updated');
set(0,'UserData','23Skidoo_Updated');
and then at a point where you were interested in knowing that your variable had changed, you could
waitfor(0,'Userdata','23Skidoo_Updated');

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!