Running functions from initial working function when in another subfolder?

8 visualizaciones (últimos 30 días)
Hi there,
I noticed that under preferences--> general the user can set the initial working folder for matlab. My friend's computer is set to "based on startup rules" and my is set to a syncd gDrive folder for convenience between my workstations. On my friend's computer he is able to store functions in his startup (initial working) folder i.e.user/docs/MATLAB and RUN THEM from any subfolder of that root. I on the other hand receive an error when I try to do this same thing user a another specified folder selected in the general preferences area.
I would like to have the same flexibility with my function placement as my friend but use the gDrive folder instead of the default user/doc/MATLAB. This allows function calls by just "function name (xx,xxx,..)" instead of specifying the full path each time.
Does anyone know a way I can make this work?
Thanks for your help!!! It is much appreciated!

Respuesta aceptada

Image Analyst
Image Analyst el 4 de Sept. de 2015
Why not just put this in your startup.m file:
addpath('g:\folder');
savepath;
  4 comentarios
Steven Lord
Steven Lord el 4 de Sept. de 2015
You can put whatever you want in your startup.m file. A mildly annoying April Fools' joke would be to modify someone's startup.m to include the command " quit force " so MATLAB shuts down on startup. [You'd have to edit startup.m in a text editor to remove the offending command.]
As listed in the See Also section of the startup.m documentation page, the finish.m file is the equivalent of startup.m for doing something when MATLAB exits rather than when MATLAB starts.
Bora Eryilmaz
Bora Eryilmaz el 12 de Nov. de 2015
Editada: Bora Eryilmaz el 12 de Nov. de 2015
It is enough to run the accepted answer once since it will save the specified folder on your MATLAB path. You don't need to rerun it from startup.m every time you start MATLAB.
You friend can run his code from anywhere because the folder "user/docs/MATLAB" is automatically on the MATLAB path, whereas yours was not.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by