Why is my initial working folder not being set properly in MATLAB R2020b?

17 Ansichten (letzte 30 Tage)
I am trying to change my initial working folder in MATLAB R2020b. I attempted to change the initial working folder in Preferences by following the steps outlined in the documentation. To access these instructions, execute the following command in the MATLAB R2020b command window:
>> web(fullfile(docroot, 'matlab/matlab_env/matlab-startup-folder.html'))
However, MATLAB still opens to a different directory.
I then tried to remove the current initial working directory using "Set Path" in the Home -> Environments tab in the Toolstrip, and by using the function "rmpath". Still, MATLAB opens to the wrong directory. How can I point MATLAB to my desired initial working directory?

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 24 Jan. 2025
Bearbeitet: MathWorks Support Team am 3 Feb. 2025
This could be because at startup MATLAB is adding a different directory to the search path than the one you have specified in your Preferences.
One reason for this could be that the function "userpath" was previously used to add the incorrect initial working directory to the search path at startup.
  • Check to see if there is a folder being added to the search path at startup by typing the command:
>> userpath
        in the Command Window.
  • If the output is non-empty, then this means that the directory returned by "userpath" is being added to the MATLAB search path at startup.
  • To clear it for all future sessions of MATLAB, execute the command:
>> userpath('clear')
  • Restart MATLAB and check to see if MATLAB opens to the correct initial working directory.
If MATLAB still opens to the incorrect directory, then this could be because the path to the incorrect initial working directory is added in a "startup.m" file. These "startup.m" files can perform different tasks, such as including additional paths to the search path and changing the working directory.
  • Check to see if there is a "startup.m" file by executing the command:
>> which startup.m
        in the Command Window.
  • If there is a "startup.m" file, open it in the MATLAB Editor.
  • Search "startup.m" to see if "addpath" or "path" is used to add the incorrect initial working directory to the startup search path.
  • If so, comment out the relevant line(s) and save the "startup.m" file.
  • Restart MATLAB and check to see if MATLAB opens to the correct initial working directory.
Please follow the link below to search for the required information regarding the current release:

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by