Skip to content
Snippets Groups Projects
Verified Commit e3ae7dec authored by Houtan Bastani's avatar Houtan Bastani
Browse files

epilogue: further simplifications

parent fc67eafd
No related branches found
No related tags found
No related merge requests found
...@@ -92,22 +92,30 @@ handles.pushbuttonEpilogue = uicontrol( ... ...@@ -92,22 +92,30 @@ handles.pushbuttonEpilogue = uicontrol( ...
function EpilogueCallback(~, ~) function EpilogueCallback(~, ~)
if isempty(handles.equations.String) if isempty(handles.equations.String)
gui_tools.show_warning('You must first enter an equation');
return return
end end
equations_str = sprintf('%s', handles.equations.String'); equations_str = sprintf('%s', handles.equations.String');
equations_str = equations_str(~isspace(equations_str)); equations_str = equations_str(~isspace(equations_str));
if equations_str(end) ~= ';' if equations_str(end) ~= ';'
gui_tools.show_warning('The last equation must end with a semicolon'); gui_tools.show_warning('Equations must end with a semicolon');
return return
end end
equations = strtrim(strsplit(equations_str, ';')); equations = strsplit(equations_str, ';');
equations = equations(~cellfun('isempty', equations)); equations = equations(~cellfun('isempty', equations));
if isempty(equations) if isempty(equations)
gui_tools.show_warning('No equations found. Did you end each equation with a semilcolon?');
return return
end end
lhs = get_lhs_var(equations); lhs = strtok(equations, '=');
rhs = get_rhs_endo_exo(equations); rhs = regexp(equations, ['\<(', strjoin([M_.endo_names ; M_.exo_names], '|'),')\>'], 'match');
max_lag = get_rhs_max_lag(equations); max_lag_eqs = regexp(equations, '\(\-(\d*)\)', 'match');
max_lag = zeros(length(max_lag_eqs), 1);
for i = 1:length(max_lag)
if ~isempty(max_lag_eqs{i})
max_lag(i) = abs(min(cellfun(@str2num, max_lag_eqs{i})));
end
end
equations = regexprep(equations, '(\w*)=', 'dseries__.$1(t)='); equations = regexprep(equations, '(\w*)=', 'dseries__.$1(t)=');
equations = regexprep(equations, ['\<(' strjoin([M_.endo_names; M_.exo_names], '|') ')(?!\()\>'], 'dseries__.$1(t)'); equations = regexprep(equations, ['\<(' strjoin([M_.endo_names; M_.exo_names], '|') ')(?!\()\>'], 'dseries__.$1(t)');
equations = regexprep(equations, ['\<(' strjoin([M_.endo_names; M_.exo_names], '|') ')\>\(\-'], 'dseries__.$1(t-'); equations = regexprep(equations, ['\<(' strjoin([M_.endo_names; M_.exo_names], '|') ')\>\(\-'], 'dseries__.$1(t-');
...@@ -130,25 +138,6 @@ handles.pushbuttonEpilogue = uicontrol( ... ...@@ -130,25 +138,6 @@ handles.pushbuttonEpilogue = uicontrol( ...
end end
fprintf(fidw, 'end\n'); fprintf(fidw, 'end\n');
fclose(fidw); fclose(fidw);
% Helper functions
function lhs = get_lhs_var(equations)
lhs = strtok(equations, '=');
end
function rhs = get_rhs_endo_exo(equations)
rhs = regexp(equations, ['\<(', strjoin([M_.endo_names ; M_.exo_names], '|'),')\>'], 'match');
end
function max_lag_arr = get_rhs_max_lag(equations)
max_lag_eqs = regexp(equations, '\(\-(\d*)\)', 'match');
max_lag_arr = zeros(length(max_lag_eqs), 1);
for idx = 1:length(max_lag_arr)
if ~isempty(max_lag_eqs{idx})
max_lag_arr(idx) = abs(min(cellfun(@str2num, max_lag_eqs{idx})));
end
end
end
end end
handles.pushbuttonClear = uicontrol( ... handles.pushbuttonClear = uicontrol( ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment