How to cancel execution of second matlab script, when started 2 scripts in a row
古いコメントを表示
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)?
採用された回答
その他の回答 (1 件)
Daniel Shub
2012 年 4 月 27 日
2 投票
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 件のコメント
Jan
2012 年 4 月 27 日
Concerning "clear all" see: http://www.mathworks.com/matlabcentral/answers/16484-good-programming-practice#answer_22301
:-)
Geert
2012 年 4 月 27 日
Daniel Shub
2012 年 4 月 27 日
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
2012 年 5 月 2 日
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!