Skip to content

Commit 571064e

Browse files
committed
Added modpath.m
1 parent 2121707 commit 571064e

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

modpath.m

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
function modpath()
2+
this_script_file_path = mfilename('fullpath') ;
3+
this_folder_path = fileparts(this_script_file_path) ;
4+
addpath(degit(genpath(fullfile(this_folder_path,'landmark-matching'))));
5+
addpath(this_folder_path) ;
6+
end
7+
8+
9+
10+
function path_no_git=degit(path_raw)
11+
% eliminate .git directories from a path string
12+
path_raw_as_array=split_path(path_raw);
13+
path_no_git_as_array=cell(0,1);
14+
for i=1:length(path_raw_as_array)
15+
k=strfind(path_raw_as_array{i},'.git');
16+
if isempty(k)
17+
path_no_git_as_array{end+1}=path_raw_as_array{i}; %#ok
18+
end
19+
end
20+
path_no_git=combine_path(path_no_git_as_array);
21+
end
22+
23+
24+
25+
function path_as_array=split_path(path)
26+
% split a path on pathsep into a cell array of single dir names
27+
i_pathsep=strfind(path,pathsep);
28+
n=length(i_pathsep)+1;
29+
path_as_array=cell(n,1);
30+
if n>0
31+
if n==1
32+
path_as_array{1}=path;
33+
else
34+
% if here, n>=2
35+
path_as_array{1}=path(1:i_pathsep(1)-1);
36+
for i=2:(n-1)
37+
path_as_array{i}=path(i_pathsep(i-1):i_pathsep(i)-1);
38+
end
39+
path_as_array{n}=path(i_pathsep(n-1)+1:end);
40+
end
41+
end
42+
end
43+
44+
45+
46+
function path=combine_path(path_as_array)
47+
% combine a cell array of dir names into a single path string
48+
n=length(path_as_array);
49+
if n>0
50+
path=path_as_array{1};
51+
for i=2:n
52+
path=[path pathsep path_as_array{i}]; %#ok
53+
end
54+
end
55+
end

0 commit comments

Comments
 (0)