1

I want to add a path like

getenv('userprofile'),'\Dropbox\Matlab\example1'

to the Matlab pathdef.m file. The system variable %userprofile% will change from computer to computer.

Adding the phrase to pathdef.m will not work though.

Is there a way to add a dynamic path to the Matlab search path?

1 Answer 1

0

You can use up = getenv('userprofile') to get the user profile path environment variable. Then use addpath(up) to add it to the path, or change the current directory to it using cd(up).

Your example with a subfolder, being '\Dropbox\Matlab\example1', would work like this:

up = getenv('userprofile');
sub = '\Dropbox\Matlab\example1';
addpath([up sub]) % or cd(__)

This works, because both up and sub are strings of characters (they are of class char). They can be concatenated using [up sub], so they form a longer string of characters, being the path to your folder of choice.

For ease, this can be put in startup.m, so every time MATLAB starts your directory of choice is added to the path.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .