sur: fix bug in lhssub when param_names was specified and simplify code

time-shift
Houtan Bastani 2019-02-11 15:12:30 +01:00
parent 0352e9025a
commit c8d04e93b9
No known key found for this signature in database
GPG Key ID: 000094FB955BE169
1 changed files with 9 additions and 9 deletions

View File

@ -73,27 +73,27 @@ if nargin == 1 && size(X, 2) ~= M_.param_nbr
end end
if ~isempty(param_names) if ~isempty(param_names)
newX = dseries(); newlhssub = dseries();
nparams = length(param_names); nparams = length(param_names);
pidxs = zeros(nparams, 1); pidxs = zeros(nparams, 1);
names = X.name; names = X.name;
for i = 1:nparams for i = 1:nparams
idx = find(strcmp(param_names{i}, names)); pidxs(i) = find(strcmp(param_names{i}, names));
if isempty(idx) if isempty(pidxs(i))
if ~isempty(eqtags) if ~isempty(eqtags)
error(['Could not find ' param_names{i} ... error(['Could not find ' param_names{i} ...
' in the provided equations specified by ' strjoin(eqtags, ',')]); ' in the provided equations specified by ' strjoin(eqtags, ',')]);
end end
error('Unspecified error. Please report'); error('Unspecified error. Please report');
end end
pidxs(i) = idx;
newX = [newX X.(names{idx})];
end end
subcols = setdiff(1:X.vobs, pidxs); subcols = setdiff(1:X.vobs, pidxs);
for i = length(subcols):-1:1 for i = 1:length(subcols)
Y = Y - M_.params(strcmp(names{subcols(i)}, M_.param_names))*X.(names{subcols(i)}); newlhssub = newlhssub + M_.params(strcmp(names{subcols(i)}, M_.param_names)) * X.(names{subcols(i)});
X = X.remove(names{subcols(i)});
end end
X = newX; Y = Y - newlhssub;
lhssub = lhssub + newlhssub;
end end
% opidxs: indexes in M_.params associated with columns of X % opidxs: indexes in M_.params associated with columns of X
@ -107,7 +107,7 @@ st = dbstack(1);
if strcmp(st(1).name, 'surgibbs') if strcmp(st(1).name, 'surgibbs')
varargout{1} = nobs; varargout{1} = nobs;
varargout{2} = opidxs; varargout{2} = opidxs;
varargout{3} = X.data; varargout{3} = X{param_names{:}}.data;
varargout{4} = Y.data; varargout{4} = Y.data;
varargout{5} = neqs; varargout{5} = neqs;
return return