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

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

Thank you for trying to help, but doesn't this assume I know the location of all the scripts I'll be running in the future? Thanks
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.
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

릴리스

R2018b

질문:

2019년 4월 26일

편집:

2019년 4월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by