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

5 次查看(过去 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
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