Running functions from initial working function when in another subfolder?
8 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Image Analyst
on 4 Sep 2015
Why not just put this in your startup.m file:
addpath('g:\folder');
savepath;
4 Comments
Steven Lord
on 4 Sep 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
on 12 Nov 2015
Edited: Bora Eryilmaz
on 12 Nov 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.
More Answers (0)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!