How to prevent Matlab from immediately running after calling Linux Command?
1 回表示 (過去 30 日間)
古いコメントを表示
unix('a4 -s ~/scripts/a4cmdf_RD_Optim.ses');
%%WAIT until .dat is finished.
get_simdata;
The unix command automatically runs Animator4 with a sessionsfile which in return creates a .dat file.
With get_simdata I read the .dat file.
BUT, the problem is that Matlab already executes the get_simdata before the Animator4 is ready with writing the .dat file. And hence, there is no .dat file yet.
How do I solve this?
Edit: I can use the Pause(3) but that is not a very Elegant option I think.
0 件のコメント
採用された回答
Daniel Shub
2013 年 3 月 28 日
I believe the unix and system commands do not return until the command you are calling return so that they can get the potential results and exit code to pass back to MATLAB. I would expect that if you do
a4 -s ~/scripts/a4cmdf_RD_Optim.ses
at the Linux command prompt, that it exits immediately. If the Linux command doesn't provide a way to telling you when it is done, there is no easy way for MATLAB to know when it is done.
3 件のコメント
Jason Ross
2013 年 3 月 28 日
You might want to consider adding some logic that will get the file size of the file, then wait, then check the size again. I won't say that I've never used a static pause, but I will say that often times, eventually I end up implementing some sort of polling interval where I started with a pause as the problem grows and starts giving me an incomplete file.
Daniel Shub
2013 年 3 月 28 日
If you cannot get an exit status, then I you might want to do something like a ps to look for when the job finishes. This might be easier to script in bash.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!