MATLAB Answers

0

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

Asked by paul harder on 26 Apr 2019
Latest activity Edited by Adam Danz
on 27 Apr 2019
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 Comment

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?

Sign in to comment.

Products


Release

R2018b

1 Answer

Adam Danz 님의 답변 26 Apr 2019
Adam Danz 님이 편집함. 26 Apr 2019

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 Comments

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.

Sign in to comment.