How can I avoid the "change folder / add to path" window when running a script?
57 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Adam Danz
el 27 de Abr. de 2019
Editada: Adam Danz
el 27 de Abr. de 2019
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?
Respuestas (1)
Adam Danz
el 26 de Abr. de 2019
Editada: Adam Danz
el 26 de Abr. de 2019
"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 comentarios
Adam Danz
el 26 de Abr. de 2019
Editada: Adam Danz
el 26 de Abr. de 2019
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
el 26 de Abr. de 2019
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.
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!