Repository navigation
Expand file tree
/
Copy pathModeling_GetVariables.m
More file actions
executable file
·70 lines (59 loc) · 2.7 KB
/
Copy pathModeling_GetVariables.m
File metadata and controls
executable file
·70 lines (59 loc) · 2.7 KB
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Janez Presern, Ales Skorjanc, Tomaz Rodic, Jan Benda 2011-2015
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Utility variables/constants from the InitialFitParam
function output=Modeling_GetVariables(Project,ModelName,varargin)
inputDir = cd;
% if an argument has been given and is not empty
if nargin > 2 && isempty(varargin{1}) == 0
% go through all inputs and converts stringed values into numbers
for st = 1: length(varargin);
varargin(st) = {num2str(varargin{st})};
end;
% collect values and names of variables that will be fitted
if strmatch('fit_',varargin);
fit_var_ind = strmatch('fit_',varargin)';
fit_var_count = 0;
for r = 1 : length(fit_var_ind);
fit_var_count = fit_var_count + 1;
fit_var_name(fit_var_count) = {strrep(varargin{fit_var_ind(r)},'fit_','')};
if fit_var_ind(r) < size(varargin,2);
if isscalar(str2num(varargin{fit_var_ind(r)+1})); fit_var(fit_var_count) = str2num(varargin{fit_var_ind(r)+1});
else fit_var(fit_var_count) = in.InitialValues.(strrep(varargin{fit_var_ind(r)},'fit_',''));
end;
else fit_var(fit_var_count) = in.InitialValues.(strrep(varargin{fit_var_ind(r)},'fit_',''));
end;
end;
end;
% collect tha values and the names of variables to fit
if strmatch('const_',varargin);
const_var_ind = strmatch('const_',varargin)';
const_var_count = 0;
for r = 1 : length(const_var_ind);
const_var_count = const_var_count + 1;
const_var_name(const_var_count) = {strrep(varargin{const_var_ind(r)},'const_','')};
if const_var_ind(r) < size(varargin,2);
if isscalar(str2num(varargin{const_var_ind(r)+1}));... % if you find a value for a constant variable change it in the InitialValue structure
in.InitialValues.(strrep(varargin{const_var_ind(r)},'const_','')) = str2num(varargin{const_var_ind(r)+1});
end;
end;
const_var(const_var_count) = in.InitialValues.(strrep(varargin{const_var_ind(r)},'const_',''));
end;
end;
else
names = fieldnames(in.InitialValues);
const_var_count = 0;
for r = 1 : length(names)
fit_var(r) = in.InitialValues.(names{r});
fit_var_name(r) = {names{r}};
end;
end;
output.fit_var = fit_var;
output.fit_var_name = fit_var_name;
if const_var_count ~= 0
output.const_var = const_var;
output.const_var_name = const_var_name;
else
output.const_var = [];
output.const_var_name = [];
end;