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

조회 수: 8 (최근 30일)
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 CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by