can't change startup directory when calling matlab with -automation from command line

8 ビュー (過去 30 日間)
Robert Wilson
Robert Wilson 2013 年 1 月 9 日
コメント済み: Andrew Lee 2014 年 6 月 24 日
Windows 7, Matlab 2007b.
I want to call Matlab to run a script from a windows 7 .bat file. I'm using the command:
matlab -automation -r myScript
The problem is that the script needs to access some files in (or relative to) the directory where the bat file is located. In theory this shouldn't be a problem since the startup directory should be the same directory as the bat file, from Matlab help:
"When you do not specify the -sd option, the startup directory is the directory from which you ran matlab"
But in practice the startup directory is the Matlab root directory: C:\Program Files\MATLAB\R2007b
I tried also explicitly setting the startup directory using:
matlab -automation -sd "%CD%" -r myScript
but the startup directory is still Matlab root.
The problem only happens with the -automation flag, if I leave that out then it works fine - but if I leave that out then Matlab takes much longer to start and it slows down my whole process.
  2 件のコメント
Robert Wilson
Robert Wilson 2013 年 1 月 9 日
Update: I've changed my command to
matlab -nojvm -nosplash -r myScript
which is working. The downside is the with no java there's no editor and I can't debug in realtime, but it's an acceptable work around for now.
Andrew Lee
Andrew Lee 2014 年 6 月 24 日
I'm experiencing the same problem in R2012b. In my case I need to utilize Java classes so the -nojvm flag isn't an option. Also, I can't use the post-launch 'cd' approach because I'm using a custom classpath.txt file in the launch directory (which doesn't get picked up when using the -automation flag).

サインインしてコメントする。

回答 (1 件)

TAB
TAB 2013 年 1 月 10 日
編集済み: TAB 2013 年 1 月 10 日
Try
set CHANGE_DIR_CMD=cd('%CD%')
matlab -automation -r "%CHANGE_DIR_CMD%;myScript"

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by