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

29 views (last 30 days)
I am trying to change my initial working folder in MATLAB R2020b. I tried to change the initial working folder in Preferences by following the steps outlined in the following documentation link: 
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?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 26 Jan 2023
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. 

More Answers (0)

Categories

Find more on Search Path in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!