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

18 次查看(过去 30 天)
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"?

回答(1 个)

MarKf
MarKf 2023-8-5
编辑:MarKf 2023-8-5
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 个评论
fa wu
fa wu 2023-8-6
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 2023-8-7
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by