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

6 vues (au cours des 30 derniers jours)
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?

Réponse acceptée

Jan
Jan le 7 Août 2013
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" &')

Plus de réponses (1)

Jochen Schuettler
Jochen Schuettler le 8 Août 2013
The startup.m was the problem - and also the reason why some very old folders kept reappearing in the path. Thank you!

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by