Pause one script but still run others?
7 次查看(过去 30 天)
显示 更早的评论
Is there a way to pause one script during exicution but still be able to execute another? What I want is to have the first script pause after opening a second script in a new tab and wait for a variable to be created when it is executed. Everything I can think of causes Matlab to say busy. Thanks in advance!
0 个评论
采纳的回答
Walter Roberson
2019-6-6
No.
In all of the ways that it is possible to run multiple scripts simultaneously, the scripts are running in separate processes, and it is not possible for one MATLAB process to monitor the internal state of a different process without the cooperation of the second process.
Normally GUIs do some work and then return back to the intepreter, and whatever invoked them then continues. Often there isn't really anything else, and the interpreter sits around until a callback is triggered, and the reacting function for that is run and then the interpreter is returned to to wait for another callback to be triggered. This sequence can be modified so that the calling function is not given back control until some particular graphics event happens (for example the user clicks a button on a confirmation dialog.) This is not having several scripts run simultaneously: at any one time one script has control and the other scripts do not progress until the first one gives up control or is interrupted in particular ways.
The mechanism to wait for a certain thing to happen is to use waitfor() passing in a description of what is being waited for.
It is not possible to wait for a particular variable to be created. It is, however, possible to wait for a particular property of a graphics object to be changed, including waiting for it to be become a particular value.
For this purpose, guidata(), the handles structure, is technically implemented as a property that you could waitfor() on, if you know the hidden ways to do that, but you cannot waitfor() a particular structure member within the handles structure. You would have a much easier time waitfor() a uicontrol pushbotton to pushed, or waitfor() Userdata of a graphics object to be changed.
3 个评论
Walter Roberson
2019-6-6
You are in a situation similar to questdlg(), where a GUI has to be brought up and actions permitted but you do not want the first one to proceed until something particular has happened in the second GUI. This is a job for waitfor(), and you can read the source for questdlg() to see how they handle matters.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!