I've been chasing the answer to this question in the MATLAB documentation for a long time...
For example, at the bottom of
http://www.mathworks.com/help/matlab/matlab_env/changing-the-startup-folder.html
it says
Use the startup.m file to specify the startup folder...
...which is plainly absurd, since elsewhere the documentation says that startup.m
is to be found in the so-called "startup folder". So therefore there's no way for this file to specify where this folder should be.
Etc., etc., etc. This sort of circularity pervades everything I've found in the docs on startup.m
.
What I want to know is: can I or can't I customize the location of the "startup folder" in a way that is persistent, and if so, where is this persistent information stored?
Create a startup. m file in the userpath folder, which is on the MATLAB search path. Add commands you want executed at startup. For example, your code might include physical constants, defaults for graphics properties, engineering conversion factors, or anything else you want predefined in your workspace.
Startup Options in MATLAB Startup File m file in a folder on the MATLAB search path. Use startup. m to modify the default search path, predefine variables in your workspace, or define defaults for graphics objects.
Description. pathdef returns a string listing of the directories in the MATLAB search path. Use path to view each directory in pathdef.
The best method, I find, is this. Let's say you want MATLAB to start up in mystartupdir
, and you've placed startup.m
in that directory.
On Windows, make a shortcut icon to MATLAB, then right-click on it and select Properties
. Edit the field Start In
. Now, use this icon whenever you want to start MATLAB.
On other platforms, you can run MATLAB with the -sd
flag to specify the startup directory:
matlab -sd mystartupdir
If you don't specify a startup directory, MATLAB will use the default specified by the userpath
command. You can place your startup.m
file there.
According to this page in the docs, you should create your own startup.m
in the "startup directory" which, if you follow the link, leads to this page explaining the definition of "startup directory" in this context.
You can retrieve this "startup directory" with the userpath
function which returns, on my system:
>> userpath ans = C:\Users\MYUSERNAME\Documents\MATLAB;
Personally, I just set the "Start In" in the shortcut to whatever I want - but obviously this won't work if you're not on Windows; if you're not on Windows or prefer not to rely on the shortcut you should create a startup.m
with a call to cd
in whatever directory userpath
returns.
The docs also say you can modify the userpath
function, if you so desire, or the matlabrc.m
file in matlabroot/toolbox/local
(but you can only do the latter if you're a MathWorks engineer or a system administrator, otherwise MathWorks will rain fiery hell down on you from above, or something...).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With