test for leads in equation

time-shift
Houtan Bastani 2017-07-06 14:31:15 +02:00
parent f78e166aa7
commit b7a8ad6b7e
2 changed files with 10 additions and 1 deletions

View File

@ -39,13 +39,17 @@ end
jsonmodel = loadjson(jsonfile);
jsonmodel = jsonmodel.model;
[lhs, rhs, ~] = getEquationsByTags(jsonmodel, varargin{:});
[lhs, rhs, lineno] = getEquationsByTags(jsonmodel, varargin{:});
Y = ds{lhs}.data;
rhs_ = strsplit(rhs, {'+','-','*','/','^','log(','exp(','(',')'});
rhs_(cellfun(@(x) all(isstrprop(x, 'digit')), rhs_)) = [];
vnames = setdiff(rhs_, cellstr(M_.param_names));
regexprnoleads = cell2mat(strcat('(', vnames, {'\(\d+\))|'}));
if ~isempty(regexp(rhs, regexprnoleads(1:end-1), 'match'))
error(['olseqs: you cannot have leads in equation on line ' lineno ': ' lhs ' = ' rhs]);
end
regexpr = cell2mat(strcat('(', vnames, {'\(-\d+\))|'}));
vwlags = regexp(rhs, regexpr(1:end-1), 'match');
X = cell2mat(cellfun(@eval, strcat('ds.', vwlags, '.data'), 'UniformOutput', false));

View File

@ -54,6 +54,11 @@ pnames = cellstr(M_.param_names);
vnames = setdiff(rhs_, pnames);
pnames = setdiff(rhs_, vnames);
regexprnoleads = cell2mat(strcat('(', vnames, {'\(\d+\))|'}));
if ~isempty(regexp(rhs, regexprnoleads(1:end-1), 'match'))
error(['plot_contributions: you cannot have leads in equation on line ' lineno ': ' lhs ' = ' rhs]);
end
% Get values for the parameters
idp = strmatch(pnames{1}, M_.param_names, 'exact');
str = sprintf('%s = M_.params(%d);', pnames{1}, idp);