Current folder is wrong after starting from command line. Why? How to fix it?
7 次查看(过去 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?
0 个评论
采纳的回答
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" &')
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!