Pause one script but still run others?

7 visualizaciones (últimos 30 días)
Davey Gregg
Davey Gregg el 6 de Jun. de 2019
Comentada: Walter Roberson el 6 de Jun. de 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!

Respuesta aceptada

Walter Roberson
Walter Roberson el 6 de Jun. de 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 comentarios
Davey Gregg
Davey Gregg el 6 de Jun. de 2019
So what I ended up doing is using the open commend to bring up the second script followed by return to stop the first. The user then runs the second and everything is cleared save for the desired variable and another open brings the first back to the front so it can be run again.
Walter Roberson
Walter Roberson el 6 de Jun. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by