How can I move the 'pathdef.m' file from its default location to another location?

조회 수: 116 (최근 30일)
I would like to put my 'pathdef.m' path file in an arbitrary directory instead of the default directory.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2024년 2월 6일
편집: MathWorks Support Team 2022년 1월 12일
By default, the 'pathdef.m' file is located in the '<matlabroot>/toolbox/local' directory, where <matlabroot> is the directory displayed after entering the following command in the MATLAB Command Window:
>> matlabroot
Another possible, supported location for 'pathdef.m' may be the userpath, where userpath is the directory displayed after entering the command in the MATLAB Command Window:
>> userpath
To move the 'pathdef.m' file from its default location to another location, it can be manually copied from this directory and placed in an arbitrary directory, or you can call 'savepath' with an input argument that specifies the full path:
>> savepath folderName/pathdef.m
In order for MATLAB to use the copied 'pathdef.m' file at initialization, create a MATLAB file titled 'startup.m' and place it in the userpath folder. Copy the lines of code below to the file. If a 'startup.m' file already exists in userpath, add the lines of code to the end of the file:
% save starting directory
startdir = pwd;
% specify arbitrary directory containing pathdef.m
pathdir = '<MODIFIED_PATH>';
% change directory so that target 'pathdef.m' has highest precedence
% in the MATLAB search path
cd(pathdir)
% set the MATLAB search path using PATH
path(pathdef)
% change directory back to the starting directory
cd(startdir)
Make sure to modify the string marked "MODIFIED_PATH" in the above code to the directory to which the 'pathdef.m' file was copied. The 'startup.m' script will be automatically executed upon MATLAB initialization.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by