How to manage relative addpath uses in subfunctions, when using SVN for example ?

62 ビュー (過去 30 日間)
Marc Crapeau
Marc Crapeau 2011 年 4 月 4 日
コメント済み: qaqcvc 2019 年 7 月 17 日
Hello,
I'm currently creating a series of matlab m-files which are monitored by SVN. The m-files are located in different sub-directories. Some of them are sub-functions and are called by a lot of different m-files. This sub-functions need some other sub-(sub-)functions and would need a use of addpath to reach them. But due to the fact that other people will retrieve my m-files in their home space, I cannot use absolute paths... And the use of relative paths with addpath for sub-functions is not possible because addpath works inside the working path, not from the place where the m-file which call it is located.
I know that SVN is used for matlab code, so I would like to know how these links are managed without using this kind of code at the begining of each function:
mfile_callers=dbstack;
if length(mfile_callers)==1
addpath('MyRelativeDir');
else
local_path=fileparts(which(mfile_callers(end-1).name));
addpath(fullfile(local_path,'MyRelativeDir'));
end

回答 (3 件)

Marc Crapeau
Marc Crapeau 2011 年 4 月 5 日
After hours of search, I have finally decided to replace my classic addpath blocks by new ones in ALL my functions, replacing for example:
addpath('../common_files');
addpath('../Readers');
by
mfilepath=fileparts(which(mfilename));
addpath(fullfile(mfilepath,'../common_files'));
addpath(fullfile(mfilepath,'../Readers'));
Not really beautiful..

Ayman Mukhaimar
Ayman Mukhaimar 2019 年 4 月 9 日
編集済み: Ayman Mukhaimar 2019 年 4 月 9 日
use one dot instead of two
addpath('./common_files');
addpath('./Readers');

Oytun Peksel
Oytun Peksel 2018 年 10 月 2 日
addpath(fullfile(pwd,'..\common_files'))

カテゴリ

Help Center および File ExchangeSearch Path についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by