Matlab question: saving the path
I am working with Matlab R2开发者_C百科011a. I want to set a path at c:\matlab (say). But it seems that the path setting is not saved and I need to reset the path every time I start Matlab. Please advise.
If you want to start Matlab in a specific path, and have that path automatically added to your search path, you modify the userpath
setting:
userpath('C:\matlab')
If you want to start Matlab in a specific path without having that path added to your search path, you have two options:
1) Create a file startup.m
in the folder C:\Program Files\MATLAB\R2011a\toolbox\local
and write in the file cd('C:\matlab')
. This way, whenever Matlab is started, it changes the path (you can also add other commands that should be executed upon startup).
2) Right-click onto the Matlab icon you normally use to start up the program, and in the properties, write C:\matlab
in the Start in
line. Thus, whenever you start Matlab from the shortcut (but not otherwise), Matlab will change path.
Make sure that you have access to all matlab files. I had the same problem, but when I gave myself full control of the C:\Program Files\MATLAB\R2012b folder (and all it's subfiles and folders) I no longer had this problem.
To do this, right click on the R2012b folder (or whichever version you have), and open properties.
Under the security tab, look for your username in the list. If it's not there, click "Edit..." and "Add..." your name. Then click the full control in the allow column. You may need an admin password for this.
Click "ok", "ok" (it may take a couple of minutes). Set the path again, close Matlab, reopen, and test if your setpath settings are still there.
To add to Jonas' answer (because changing the user path didn't work for me):
You can also use the start.m method "If you want to start Matlab in a specific path, and have that path automatically added to your search path". For Linux:
start.m
cd /path/to/my/folder % sets current working directory
addpath(genpath('/path/to/my/folder')) % adds directory (and its subfolders) to the path list
or for Window I suppose it would look like this:
start.m
cd c:\path\to\my\folder % sets current working directory
addpath(genpath('c:\path\to\my\folder')) % adds directory (and its subfolders) to the path list
精彩评论