How can I avoid the "change folder / add to path" window when running a script?

84 ビュー (過去 30 日間)
paul harder
paul harder 2019 年 4 月 26 日
編集済み: Adam Danz 2019 年 4 月 27 日
This window pops up every time I run a new script, and I always click "add to path." I know how to use the addpath or cd functions within my script to make this go away the next time I run the script, but I still think I've clicked this button a couple thousand times in my life. Is there a way I can avoid it?
Please note that I'm always running scripts from various new project folders, so adding certian folders to matlab's startup routine is not a future-proof option for me.
thank you!
  1 件のコメント
Adam Danz
Adam Danz 2019 年 4 月 27 日
編集済み: Adam Danz 2019 年 4 月 27 日
In response to your edited question, are you saying that the location of your files is completely unpredictable? That sounds like more of a organizational problem. Usually files are stored in subdirectories within a main directory, or if you're using a network within a couple main directories. With that organization, you can simply add all of the paths that lead to all of your needed files during startup.
You mentioned you add the paths when you're prompted, so I assume you know where the files are. What's preventing you from adding those paths to the startup file?

サインインしてコメントする。

回答 (1 件)

Adam Danz
Adam Danz 2019 年 4 月 26 日
編集済み: Adam Danz 2019 年 4 月 26 日
Paul, start a startup.m file and store it in your main matlab folder. From the documentation,
"At startup, MATLAB automatically executes the matlabrc.m file and startup.m, if it exists on the MATLAB search path. The file matlabrc.m, which is in the matlabroot/toolbox/localfolder, is reserved for use by MathWorks® and by system administrators on multiuser systems."
In your startup.m file, add all necessary paths to run your scripts, functions, and other files that matlab needs access to.
Next time (and every time) you start matlab, the paths will be added automatically.
  3 件のコメント
Adam Danz
Adam Danz 2019 年 4 月 26 日
編集済み: Adam Danz 2019 年 4 月 26 日
Yes, you need to tell matlab where to look and there's no way around that. Your files shouldn't be scattered all over the place anyway.
You don't need to list the exact subfolder. For example, if you have a lot of subfolders, all of which contain matlab codes, you can recursively add all of their paths like this:
addpath (genpath('C:\Users\name\Documents\MATLAB'))
That line would add paths to all directories and sub-directories within the Matlab folder.
If you often connect to a network or remove computer, you can write a conditional in your startup file that detects whether you're connected and conditionally add those paths, too.
This is a common workflow.
Adam Danz
Adam Danz 2019 年 4 月 26 日
An additional recommendation is to add a 'favorite' command that you can quickly run every time you access a network or remote computer after startup has already run.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by