How to cancel execution of second matlab script, when started 2 scripts in a row
Mostrar comentarios más antiguos
Here's a problem I had for several years now, and never found an easy solution for it.
I have two matlab scripts, say script1.m and script2.m. These are both scripts which take several hours of calculation. I ran script1.m and waited for a couple of hours. Next (while script1.m was still executing) I accidently pressed the "Run" button for script2.m in the same matlab window. script2.m starts with "close all; clear all;" and hence all my results will be erased when script2.m starts, which is like 1 millisecond after the completion of script1.m. Is there a way to prevent matlab from executing script2.m (without changing my programming style)?
I could ofcourse modify script2.m and put the command "return" on its first line and save it, but I would love to know if there's a more elegant way of doing this (without changing my programming style)?
Respuesta aceptada
Más respuestas (1)
Daniel Shub
el 27 de Abr. de 2012
2 votos
Yes, there is a more elegant way. Convert script 1 and 2 into functions. Use structures to store and pass your variables.
I am going to let Jan handle the inelegance of "clear all" ...
4 comentarios
Jan
el 27 de Abr. de 2012
Concerning "clear all" see: http://www.mathworks.com/matlabcentral/answers/16484-good-programming-practice#answer_22301
:-)
Geert
el 27 de Abr. de 2012
Daniel Shub
el 27 de Abr. de 2012
You should modify your question to give us all the constraints. You asked in your question if it could be done and done in an elegant way. I told you yes. No you come back and say without changing your programing style. If that is a requirement, then you should add it to your question.
Geert
el 2 de Mayo de 2012
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!