6
votes

I have a handful of scripts and data in different folders and I use addpath and relative paths very often. My problem is, this only works if my current folder is where the script that I execute is located. For example, if I execute script A which adds path X and later execute script B which lies in path X, Matlab doesn't automatically change the folder and relative paths specified in script B don't work anymore.

Is there a way to automatically set my current folder to the location of the script I'm executing?

/edit: I should note that I use these scripts on different computers with different drive names, so using absolute paths probably won't help.

1

1 Answers

9
votes

Put the following line in the script, it would set the current directory = script directory

cd(fileparts(mfilename('fullpath')))