Is $USERDATA/pathdef.m for local path additions supported on Linux?

3 次查看(过去 30 天)
What I have: I'm using MATLAB on a Linux cluster, where I have a personal node that has my USERPATH folder ~/Documents/MATLAB on it. However, I lack control over the MATLAB install ( MATLABROOT is /usr/local/apps/matlab-2013a ) and its associated pathdef.m file ( /usr/local/apps/matlab-2013a/toolbox/local/pathdef.m ).
What I want: I want to be able to start a MATLAB session anywhere on my filesystem and have it automatically load a custom pathdef.m that adds my group's custom MATLAB functions to the path on startup. As far as I could tell, the way to do this is to save my custom paths to my USERDATA/pathdef.m, and this is the way I want to.
The problem: If I start a MATLAB session anywhere that is not ~/Documents/MATLAB aka USERPATH, then the custom path additions in ~/Documents/MATLAB/pathdef.m are NOT added to the path on startup (and therefore I can't call the functions) -- even though, when I run which pathdef -all, my ~/Documents/MATLAB/pathdef.m file IS listed above MATLABROOT's pathdef.m! It's definitely seeing my USERPATH/pathdef.m on startup (even starting a session in a different location) but curiously it seems like it's not actually processing the file. I have tested this with 2013a and 2014b.
I know questions about content similar to this one have been asked in abundance before, but I've never seen anyone or any documentation confirm if "path additions are added to the search path at startup not just by MATLABROOT's pathdef.m but also USERPATH's pathdef.m on Linux, if one starts a MATLAB session not in the USERPATH directory". If this is not the case, and the user can't control MATLABROOT's pathdef.m, then I don't know of a way a user can specify additional paths on startup using pathdef or USERPATH outside of always having a pathdef.m file in whatever directory the session is started in (thereby requiring them to always start MATLAB in the same directory).
I want to emphasize again that ~/Documents/MATLAB/pathdef.m IS listed in the pathdefs via which pathdef -all, but its additional paths are NOT accessible, and are not displayed when I run path.
  1 个评论
Austin Soplata
Austin Soplata 2016-2-22
A colleague tested putting addpath(genpath('/path/to/code/repo')); into my ~/Documents/MATLAB/startup.m and this seemed to work globally! So while that's not using pathdef.m, that did seem to get the job done, for anyone looking for a solution!

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2016-2-22
编辑:Jan 2016-2-22
The USERPATH is appended to the path inside MATLABROOT's pathdef.m. So when pathdef.m is called on startup, the USERPATH's pathdef.m is not visible. See the contents of matlabrc.m, where pathdef.m is called.
User additions tothe path are more reliable in a user defined startup.m, which is called after the USERPATH is added to the path. Relying on the pathdef.m file is the startup directory implies, that this depends on the startup directory.
  1 个评论
Austin Soplata
Austin Soplata 2016-2-22
Thanks Jan! Just to clarify, does this mean that, like Highlander, "there can only be one" pathdef.m? In other words, if MATLABROOT has a pathdef.m, then there's no point in having any other pathdef.m file since only MATLABROOT's will be read? Thanks again

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Search Path 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by