forked from datajoint/mym
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mym.m
48 lines (48 loc) · 1.65 KB
/
mym.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
% setupMYM (invoked only first time to set path and removes itself)
function varargout = mym(varargin)
warning('mYm:Setup:FirstInvocation', 'Setting mym to path as first invocation.');
% determine state
origDir = pwd;
ext = dbstack;
ext = ext.file;
[~,~,ext] = fileparts(ext);
filename = [mfilename('fullpath') ext];
% add to mex-path as appropriate (persist)
toolboxName = 'mym';
s = settings;
if verLessThan('matlab', '9.5')
toolboxRoot = [strrep(s.matlab.addons.InstallationFolder.ActiveValue, '\', '/') ...
'/Toolboxes/' toolboxName '/code'];
else
toolboxRoot = [strrep(s.matlab.addons.InstallationFolder.ActiveValue, '\', '/') ...
'/Toolboxes/' toolboxName];
end
mymPath = [toolboxRoot '/distribution/' mexext];
addpath(mymPath);
pathfile = fullfile(userpath, 'startup.m');
if exist(pathfile, 'file') == 2
fid = fopen(pathfile, 'r');
f = fread(fid, '*char')';
fclose(fid);
if ~contains(f, ['addpath(''' mymPath ''');'])
f = [['addpath(''' mymPath ''');'] newline f];
fid = fopen(pathfile, 'w');
fprintf(fid, '%s', f);
fclose(fid);
end
elseif exist(pathfile, 'file') == 0
fid = fopen(pathfile, 'a+');
fprintf(fid, '\n%s\n',['addpath(''' mymPath ''');']);
fclose(fid);
end
% determine proper mym response and restore state
cd(mymPath);
if nargout
[varargout{1:nargout}] = mym(varargin{:});
else
mym(varargin{:});
end
cd(origDir);
% remove file to prevent collisions
delete(filename);
end