Current folder is wrong after starting from command line. Why? How to fix it?

조회 수: 6 (최근 30일)
Matlab has a nifty feature: When started from (Windows) command line, it takes the current directory from there. With my installation that fails. During initialization it is correct, as can be seen in the directory window. But at the end of initialization it switches to the standard folder! THEN it runs the -r option and cannot find the referenced m-script file.
Why is that so? How to fix it?
By the way, is there any way to let a running instance of Matlab run a m-script from (Windows) command line, instead of letting a new instance open?

채택된 답변

Jan
Jan 2013년 8월 7일
Does the switch to the standard folder happen inside a user-defined startup.m function?
Here you find a description of the troubles I had, when I had started Matlab from another Matlab session and the parent folder of strncmp.m was the current folder in the caller. This means, that the folder is kept initially and the userpath is activated later on.
A solution might be to cd to the wanted folder:
system('matlab -r "cd(''C:\Temp''); yourFunction" &')

추가 답변 (1개)

Jochen Schuettler
Jochen Schuettler 2013년 8월 8일
The startup.m was the problem - and also the reason why some very old folders kept reappearing in the path. Thank you!

카테고리

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