필터 지우기
필터 지우기

Adding matlab paths temporarily

조회 수: 51 (최근 30일)
SandeepKumar R
SandeepKumar R 2019년 4월 16일
답변: Walter Roberson 2019년 4월 16일
I have 2 functions with same names in 2 different folders A and B. Lets call the function as func.m
I have another main program where I will be calling this function.
I want to specify the folder from which func() will be used from.
addpath causes the added path to remain until the matlab session is closed and rmpath can be used to remove the path but it causes issues at times by accessing the wrong folder.
Is is possible to addpaths that will be used only when the script is run ? I don't want the path to be there for the entire matlab session.

채택된 답변

Walter Roberson
Walter Roberson 2019년 4월 16일
path() can be used to change the entire path. So you could call path to record the path, and addpath, and then before return path(oldpath)
If you were using functions I would suggest an onCleanup.
I would recommend enclosing most of the script with try/catch where the catch restored the path and then rethrow() and the normal branch just restored the path.
You still have problems with control C or out of memory as you cannot catch those.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by