Pause one script but still run others?
7 views (last 30 days)
Show older comments
Davey Gregg
on 6 Jun 2019
Commented: Walter Roberson
on 6 Jun 2019
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 Comments
Accepted Answer
Walter Roberson
on 6 Jun 2019
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 Comments
Walter Roberson
on 6 Jun 2019
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.
More Answers (0)
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!