Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What determines the location of the 'pathdef.m' file on Windows?

http://www.mathworks.com/support/solutions/en/data/1-5YQCPR/index.html?product=ML says:

By default, the 'pathdef.m' file may be located in either the '$MATLABROOT/toolbox/local' directory or the '$USERPATH' directory, where $MATLABROOT and $USERPATH are the directories displayed after entering the commands matlabroot (e.g. C:\Program Files\MATLAB\R2013b) and userpath (e.g. C:\Users\francky\Documents\MATLAB)

So, what determines the location of the pathdef.m file on Windows (matlabroot vs. userpath)?

like image 713
Franck Dernoncourt Avatar asked Dec 02 '25 05:12

Franck Dernoncourt


1 Answers

According to this help page:

By default, pathdef.m is in matlabroot/toolbox/local.

However, there is apparently more to it than that.

If we add matlabpath to the top of matlabrc.m, it will tell use the search path before it has even "set up" the search path:

        MATLABPATH

    C:\Program Files (x86)\MATLAB\R2013a\toolbox\local
>> 

So the only thing on the path is matlabroot/toolbox/local and that's where MATLAB will find pathdef.m by default. Right? I thought so, but a simple test with a pathdef.m in userpath proved that in fact userpath was the first priority for pathdef.m. Why? Because in MATLAB, the working directory takes priority over anything on the matlabpath, and the startup folder is determined by userpath!

There are multiple ways to specify the startup working directory, with and without the use of userpath's functional form. I just verified that changing the "Start in:" property of the Windows shortcut will prevent the pathdef.m in the default userpath from running. You can achieve the same change in startup folder with the userpath(path) syntax, but then what would be the difference between the startup path and userpath unless you use the shortcut "Start in:" method?

To add to the confusion, the last line of the default pathdef.m under matlabroot/toolbox/local is p = [userpath,p];, so after matlabrc.m adds this to the path on startup, MATLAB will then give userpath precedence over matlabroot, if ther is a pathdef.m under userpath.

like image 116
chappjc Avatar answered Dec 03 '25 17:12

chappjc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!