필터 지우기
필터 지우기

command path and pathdef

조회 수: 18 (최근 30일)
Douglas Alves
Douglas Alves 2014년 5월 28일
편집: Matt J 2014년 5월 28일
I'm trying to understand a code and there's the first line of it. Could anyone explain me what exactly this works ? The code is at the beginning what kind of conflict will I bump into if I don't do it?? What does it mean by "Avoinds naming conflicts". when I type pathdef in the prompt window it returns me a huge line with a bunch of paths what does it mean? doc pathdef didn't help very much..
% Resets the path to the initial state. Avoids naming conflicts.
path(pathdef);

채택된 답변

Matt J
Matt J 2014년 5월 28일
편집: Matt J 2014년 5월 28일
It looks equivalent to the command restoredefaultpath(), erasing any modifications you've made to the MATLAB path. If you do this, and you are trying to run code (written by you) not located in your current directory, MATLAB may not be able to find it, unless there are later lines of code which build the appropriate path.
If you are deploying this code to somebody else's machine, doing this can be a way to ensure that any modifications they've made to their MATLAB path will be erased. This can be good because maybe they have user-written code on their path that will have precedence that you don't want. On the other hand, you will break their preferred path. When they want to resume work with their own code, they will have to rebuild their preferred path in some way. This could be a pain for them, if they don't have it saved, or if they don't have a startup.m file which generates it automatically.

추가 답변 (1개)

Julia
Julia 2014년 5월 28일
As I see it pathdef.m contains all Matlab paths (you can also view them when you click on "Set path" in the "Home"-Tab) and path(pathdef) sets the path(s) your programme should be using to those paths stored as Matlab paths.
I don't know your programme, so I cannot say what is meant by "Avoids naming conflicts". Does your file create new directories/files?
If so, I think path(pathdef) ensures uniqueness of the paths to this new directories/files.
  댓글 수: 2
Douglas Alves
Douglas Alves 2014년 5월 28일
It's a kind of 'ODEsolver' but created to a particular solution. So it basically jumps from .m file to .m file. The first .m file is actually a call to the other files. It's kinda huge and there are a lot of files that's kind of impossible to post it here. I just would like to have an overview about pathdef.. Whatever kind of code is in your mind right now how does it ensure uniqueness of the paths to new files? I just ran the program without this line and nothing changed anyways. In this case it seems to be a useless line.
Julia
Julia 2014년 5월 28일
pathdef.m is only a file which contains the Matlab paths.
The paths are more clearly represented in the Set paths window.
I think this first line is there to ensure that you run your programme in the right directory. So if you cleared the line and nothing changed I assume that your default directoty is the right one.

댓글을 달려면 로그인하십시오.

카테고리

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