function to wait for a variable to change value

8 次查看(过去 30 天)
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!

回答(1 个)

Walter Roberson
Walter Roberson 2011-10-21
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');

类别

Help CenterFile Exchange 中查找有关 Graphics Object Properties 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by