forked from Remi-Gau/template_matlab_analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.m
81 lines (62 loc) · 1.81 KB
/
setup.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
function setup()
%
% USAGE::
%
% setup()
%
% - Add code to the path
% - Check if MATLAB / Octave version requirements
% - Octave > 4
% - MATLAB >= R2015b
% - For Octave loads extra packages
%
%
% (C) Copyright 2022 Remi Gau
octave_min_version = '4.0.3';
matlab_min_version = '8.6.0';
package_list = {'io', 'statistics', 'image'};
disp('Adding code to the path.');
pth = fileparts(mfilename('fullpath'));
addpath(genpath(fullfile(pth, 'src')));
% add libraries here
lib_directory = fullfile(root_dir(), 'lib'); %#ok<NASGU>
disp('checking MATLAB / Octave version.');
if is_octave()
% Exit if min version is not satisfied
if ~compare_versions(OCTAVE_VERSION, octave_min_version, '>=')
error('Minimum required Octave version: %s', octave_min_version);
end
for ii = 1:length(package_list)
package_name = package_list{ii};
try
% Try loading Octave packages
disp(['loading ' package_name]);
pkg('load', package_name);
catch
try_install_from_forge(package_name);
end
end
else % MATLAB
if verLessThan('matlab', matlab_min_version)
error('Sorry, minimum required version is R2017b. :(');
end
end
end
function try_install_from_forge(package_name)
%
% Attempt twice in case of installation fails
%
errorcount = 1;
while errorcount
try
pkg('install', '-forge', package_name);
pkg('load', package_name);
errorcount = 0;
catch err
errorcount = errorcount + 1;
if errorcount > 2
error(err.message);
end
end
end
end