Why is the working directory opening to the launch directory upon launch?

조회 수: 2 (최근 30일)
Peter
Peter 2021년 10월 14일
댓글: Peter 2021년 10월 14일
Every time I launch MATLAB, the current folder opens to the directory that was used to launch the application.
  • If I launch the application by double clicking the executable file, the Current Folder is set to the location of the executable. In my case that is C:\Program Files\MATLAB\R2019b\bin.
  • I often launch instead using an AutoHotkey script. That script just calls 'run' on the executable mentioned above. For some reason when I launch MATLAB in this way, the Current Folder is set to the folder that the AutoHotKey script is stored in.
I have set my preferences to open to a specific directory each time under Preferences - General - Initial working folder. However, this is ignored, and the folder is set each time as described above.
I have also tried instead selecting the "Last working folder from previous MATLAB session option" here. Unfortunatly that did not fix the issue, and it still opens to the same wrong directory each time.

채택된 답변

Image Analyst
Image Analyst 2021년 10월 14일
Not sure why your preference is not adhered to. Try this workaround by setting the folder in your startup.m file:
>>edit startup.m
then in there, type
cd('c:\myFolder'); % Wherever you want.
fprintf('Done running "%s".\n', mfilename("fullpath"));
then save it and run it or restart MATLAB, which should run it automatically.
  댓글 수: 1
Peter
Peter 2021년 10월 14일
That workaround worked for me, thanks! It would be interesting to find out what when wrong on my system to cause this issue, but at least it launches correctly now.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by