Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dynare
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stéphane Adjemian
dynare
Commits
6106b951
Commit
6106b951
authored
10 years ago
by
Stéphane Adjemian
Browse files
Options
Downloads
Patches
Plain Diff
Added the possibility to use parameters in a from-to-do statement.
parent
affa020e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
matlab/utilities/dseries/from.m
+35
-2
35 additions, 2 deletions
matlab/utilities/dseries/from.m
with
35 additions
and
2 deletions
matlab/utilities/dseries/from.m
+
35
−
2
View file @
6106b951
...
...
@@ -64,6 +64,9 @@ EXPRESSION = char([varargin{5:end}]);
% Get all the variables involved in the recursive expression.
variables
=
unique
(
regexpi
(
EXPRESSION
,
'\w*\(t\)|\w*\(t\-\d\)|\w*\(t\+\d\)'
,
'match'
));
% Copy EXPRESSION in expression. In the next loop we will remove all indexed variables from expression.
expression
=
EXPRESSION
;
% Build an incidence table (max lag/lead for each variable)
%
% Column 1: Name of the variable.
...
...
@@ -77,6 +80,7 @@ variables = unique(regexpi(EXPRESSION, '\w*\(t\)|\w*\(t\-\d\)|\w*\(t\+\d\)','mat
leadlagtable
=
cell
(
0
,
6
);
% Loop over the variables (dseries objects).
for
i
=
1
:
length
(
variables
)
expression
=
strrep
(
expression
,
variables
{
i
},
''
);
current
=
~
isempty
(
regexpi
(
variables
{
i
},
'\(t\)'
));
lag
=
~
isempty
(
regexpi
(
variables
{
i
},
'\(t\-\d\)'
));
lead
=
~
isempty
(
regexpi
(
variables
{
i
},
'\(t\+\d\)'
));
...
...
@@ -222,6 +226,13 @@ t2 = find(d2==tmp.dates);
% Get data
data
=
tmp
.
data
;
% Isolate the (potential) parameters in the expression to be evaluated
[
~
,
TMP314
]
=
strsplit
(
expression
,
'([0-9]*\.[0-9]*|\w*)'
,
'DelimiterType'
,
'RegularExpression'
,
'CollapseDelimiters'
,
false
);
% Here I remove the numbers (TMP314 -> TMP314159).
TMP3141
=
regexp
(
TMP314
,
'(([0-9]*\.[0-9]*)|([0-9]*))'
,
'match'
);
TMP31415
=
find
(
cellfun
(
@
isempty
,
TMP3141
));
TMP314159
=
TMP314
(
TMP31415
);
if
dynamicmodel
% Transform EXPRESSION by replacing calls to the dseries objects by references to data.
for
i
=
1
:
number_of_variables
...
...
@@ -235,6 +246,18 @@ if dynamicmodel
EXPRESSION
=
regexprep
(
EXPRESSION
,
sprintf
(
'%s\\(t+%s\\)'
,
leadlagtable
{
i
,
1
},
num2str
(
lead
)),
sprintf
(
'data(t+%s,%s)'
,
num2str
(
lead
),
num2str
(
i
)));
end
end
% Get values for the parameters (if any)
if
~
isempty
(
TMP314159
)
for
i
=
1
:
length
(
TMP314159
)
wordcandidate
=
TMP314159
{
i
};
try
% If succesful, word is a reference to a variable in the caller function/script.
thiswordisaparameter
=
evalin
(
'caller'
,
wordcandidate
);
eval
(
sprintf
(
'%s = thiswordisaparameter;'
,
wordcandidate
));
catch
% I assume that word is a reference to a function.
end
end
end
% Do the job. Evaluate the recursion.
eval
(
sprintf
(
'for t=%s:%s, %s; end'
,
num2str
(
t1
),
num2str
(
t2
),
EXPRESSION
));
else
...
...
@@ -254,6 +277,18 @@ else
EXPRESSION
=
strrep
(
EXPRESSION
,
'^'
,
'.^'
);
EXPRESSION
=
strrep
(
EXPRESSION
,
'*'
,
'.*'
);
EXPRESSION
=
strrep
(
EXPRESSION
,
'/'
,
'./'
);
% Get values for the parameters (if any)
if
~
isempty
(
TMP314159
)
for
i
=
1
:
length
(
TMP314159
)
wordcandidate
=
TMP314159
{
i
};
try
% If succesful, word is a reference to a variable in the caller function/script.
thiswordisaparameter
=
evalin
(
'caller'
,
wordcandidate
);
eval
(
sprintf
(
'%s = thiswordisaparameter;'
,
wordcandidate
));
catch
% I assume that word is a reference to a function.
end
end
end
% Do the job. Evaluate the static expression.
eval
(
sprintf
(
'%s;'
,
EXPRESSION
));
end
...
...
@@ -261,8 +296,6 @@ end
% Put assigned variable back in the caller workspace...
eval
(
sprintf
(
'assignin(
''
caller
''
,
''
%s
''
, dseries(data(:,indva),y.init,y.name,y.tex));'
,
assignedvariablename
))
function
msg
=
get_error_message_0
(
msg
)
if
~
nargin
msg
=
sprintf
(
'Wrong syntax! The correct syntax is:\n\n'
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment