Looks like using the full path cause Matlab to change working directory. Removing it fixed the issue. Case closed!
Running script from command line changes working directory to script's directory
15 ビュー (過去 30 日間)
古いコメントを表示
Dear all,
I have a problem keeping the working directory when running a script from command line. I have a script saved in my Matlab script directory, and I call it with
matlab -nodisplay -nodesktop -r "run('/path/to/Matlab/scripts/folder/the_script.m')"
The script is supposed to work on some files in the current directory, but when I call it from within the directory, it cannot find the files because Matlab's working directory changes to where the script is. How can avoid that without changing directory back to my working directory implicitly in the script?
2 件のコメント
Fangjun Jiang
2018 年 4 月 30 日
The behavior you observed is caused by run(). You can see "help run" to find the description.
-r option means to execute a statement, a function or a script. You could use below, without full folder specification if it is in the MATLAB path.
matlab -nodisplay -nodesktop -r the_script
回答 (1 件)
Fangjun Jiang
2018 年 4 月 30 日
In this case, I would suggest adding your MATLAB script directory into MATLAB path.
参考
カテゴリ
Help Center および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!