Clear Filters
Clear Filters

What is the difference between the userpath and the startup folder?

19 views (last 30 days)
I know how to config Startup Folder! I think it is very similar between the userpath and Startup Folder!
I save my *.m file in the Startup Folder. Startup Folder is in the Search Path.
Is there any case of "Startup Folder is not a userpath,or userpath is not a Startup Folder"?

Answers (1)

MarKf
MarKf on 5 Aug 2023
Edited: MarKf on 5 Aug 2023
They are different. Matlab starts in the startup folder, the initial working folder, it's displayed on the "Current Folder" panel, in the Toolbar and with the command pwd right after Matlab starts, before you or a script optionally change it with cd. You can set it also in your personal startup script you can put in userpath. It is suggested that you set your startup folder as your userpath (in the link above it even lists the advantages) but it's not a requirement. Also, if you open a file with Matlab (like an .m file which you doubleclick on it and you have Matlab set to open it) then it will start in the folder the file is in, for convenience, then it's likely to be different anyway. Otherwise Matlab starts in the startup folder (I like the preference "Last working folder from previous session") when you just open it from the Matlab icon. They are both in your search path automatically.
  2 Comments
fa wu
fa wu on 6 Aug 2023
Thanks for your answer.
"userpath(newpath) sets the user-specific folder on the search path to newpath."------ use "userpath(newpath) " to set a folder(like xyz folder)on the search path.Is there any defference between the 'xyz folder' and other folder in the search path?
MarKf
MarKf on 7 Aug 2023
Not much really, except that you put the startup script (an .m file that gets run at Matlab startup, you can add whatever you need in there) in the userpath folder. The folder is added automatically and it stays in your search path every time matlab starts, like all the other default matlab toolbox folders (but it's somewhat less convenient to change those in the MATLABPATH environment variable), and like any of those you can even remove it with pathtool (or with userpath('clear')). I guess by using the userpath, you can add the scripts you always need there, whereas the initial working folder could be changed with different projects. But a good folder management with checks adding folders and toolboxes you need is always a good idea anyway regardless.

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!